JavaRush /Java Blog /Random EN /How programming skills helped me get money back for a los...

How programming skills helped me get money back for a lost stroller

Published in the Random EN group
The author of the original article, Kristóf Litavecz , learned to program in 2017. There are no major changes to his developer career (yet!), but this story shows that programming skills can be useful in everyday life. Some even argue that the ability to write code is becoming the fourth literacy.
How programming skills helped me get money back for a lost stroller - 1
Last summer, my wife and our two children flew from Hungary to California to visit friends. Among all the difficulties of the flight, our airline lost a baby stroller along the way. My numerous attempts to contact the airline via email, Twitter, polite and then not so polite calls to cover our expenses came to nothing. I realized that I had had enough and decided to act differently. I created a Twitter bot that responded to every tweet from the airline's account to remind them of our case, which had already been pending for three months. I did not do this for the purpose of revenge or extortion of money, no, under no circumstances. I just wanted justice and coverage for my lost baby stroller. At this point, I had been studying programming for about a year and actively used the freeCodeCamp community for support and inspiration. What I've done
  1. I created a new environment on the Cloud9 dev cloud platform ( you are familiar with it if you took the CS50 course - editor's note );
  2. Created an account on Twitter;
  3. Created a simple Twitter bot using Node.js;
  4. I set it up to randomly tweet one of ten reminders every hour;
  5. And he launched it.
A week and a half later, money arrived in my account and I bought a new stroller. I posted my code in the GitHub repository . So, if you suddenly find yourself in a similar situation, take advantage.

How to do it

Step 1. Create a new environment in Cloud9 IDE Login to Cloud9 and create a new workspace. Select Node.js as the template.
How programming skills helped me get money back for a lost stroller - 2
If you want to copy my bot, simply clone my repository by entering the following line into your terminal: git clone https://github.com/krizsoo/twitterbot Step 2: Create a Twitter account and Twitter app If you don't already have a Twitter account, create it . Once you sign up, you can create a new application that will give you access to the Twitter API and you can generate tweets programmatically.
How programming skills helped me get money back for a lost stroller - 3
Once my application was configured, I received the four security keys needed to access the API:
How programming skills helped me get money back for a lost stroller - 4
  • Consumer Key (API Key) - consumer key
  • Consumer Secret (API Secret) is a kind of “login + password” for your application
  • Access Token - access token
  • Access Token Secret - access token secret
All the above keys must be added to the config.js file as follows:
How programming skills helped me get money back for a lost stroller - 5
Step 3: Set up the Twitter Bot I needed to tweak the configurations to make sure the Bot does what it needs to do.
  1. Install Node.js dependencies

    npm install --save twitter

  2. Set up your search query
You need to determine the search query that the Bot responds to. I went into the “app.js” file and updated the search parameters.
  • q- keywords;
  • count— the number of tweets that the request should return;
  • result_type— sorting logic, in our case it shows the most recent tweet first;
  • langis a language (for example, English)
The below configuration will automatically respond to the most recent tweet that contains “@lostbabystroller”.
// Set up your search parameters
var params = {
  q: '@lostbabystroller',
  count: 1,
  result_type: 'recent',
  lang: 'en'
};
Step 4: Set up tweets The bot was triggering every hour, and I didn't want it to repeat the same message all the time. So I created about 10 tweets, and the Bot randomly selected a message each time. Important: Johnny Asmar recommends making sure you don't mention people in your answers. This is contrary to Twitter's TOS. Step 5. Set up the frequency of tweets. I configured the Bot to fire every hour. First I created a variable that represents the hour in milliseconds:
//задание временного интервала твитов
var INTERVAL = 1*60*60*1000;
Then I made sure that the Bot was launched correctly:
// Start bot and timer
BotStart();
setInterval(BotStart, INTERVAL);
Step 6. Launch the Bot Once everything was set up, I launched the Bot and waited patiently.
npm run serve

What lesson did I learn from all this?

To my surprise, a customer service representative contacted me within 24 hours. I was told that there would be a money transfer. A year ago I would not have been able to do this. And although I solved a small problem, it was a triumph. I was overwhelmed with joy that I succeeded! I hope all beginners will be inspired by my story. I must say to all those who rack their brains at night writing programs - no matter whether you decide to make a career as a developer or not, understanding a computer language will definitely come in handy one day. Acknowledgments This post would not have been written without the freeCodeCamp community and the CS50 team. I am grateful to them for their support. Thanks also to Brandon Morelli and Scott Spence for writing these detailed Twitter Bot tutorials: https://codeburst.io/build-a-simple-twitter-bot-with-node-js-in-just-38-lines-of-code -ed92db9eb078 https://medium.freecodecamp.org/easily-set-up-your-own-twitter-bot-4aeed5e61f7f Source link: https://medium.freecodecamp.org/how-i-used-my-programming -skills-to-buy-a-stroller-2778cb85e8b2
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION