This tutorial will show you how to send tweets from your Medium One Sandbox account. We will create a twitter accounts for your Medium One account and send a daily tweet such as the current weather.
Here’s what you need to get started:
- Medium One Sandbox account [Buy-here]
- WiFi Internet Access
Step 1. Create a twitter account
If you don’t have a twitter account, create one with your name as your username.
On your laptop, go to www.twitter.com and join. Enter your name and mobile phone number.
Twitter will send a text to your phone to verify.
Follow the remaining twitter instructions to enter your email and choose a username (personal username).
Now you have a new twitter page. Keep this page open on the same laptop where you will login to your Medium One account. This allows us to link your Medium One account with your Twitter account which we will do in the next step.
Step 2. Link your twitter account to your Medium One account.
Login to your Medium One Sandbox account.
In the left-hand menu, select External APIs, then click on Add New Service Key.
“Connect an External Service” will display. Select Service, then twitter from the pulldown window.
Click Save and Activate. You will see twitter added as an external API.
Authorize Medium One to use your twitter account. Click Authorize app.
Once authorized, your Medium One Sandbox account will acknowledge that it is linked to your twitter account.
Step 3. Create a workflow to Send a Tweet
If you do not have any users in your Medium One sandbox, then create at least one. Go to Manage Users (left-hand menu) and click Add New User. We will create a fictitious User1 and Save.
Let’s send a tweet every noon hour of the current weather for our location. Click on the Workflow Studio icon and then the Create workflow box. Enter the name of the workflow, Send Tweet, and click anywhere inside the workflow studio edit window.
- Select Tags & Triggers
- Select Scheduler and click on Daily.
- Double click on Daily and select User1, set Schedule to 12:00pm, set Timezone to America/Los Angeles. Click Save.
Add Code module:
- Select Modules
- Select Foundation and drag Base Python to the workflow editor window.
Connect Inputs to Code module:
- Connect Daily to Base Python.
Replace the Base Python code
This code uses the pre-existing Module Library Weather.get_weather_by_coordinates(lat, lon). It gets the current weather at the latitude and longitude specified. We are using the latitude and longitude for Santa Clara, California. Note: You can change this to any city by googling that city’s latitude and longitude and replacing it in this code.
#Latitude and Longitude for Santa Clara, California
lat = 37.426048
lon = -121.975243
weather = Weather.get_weather_by_<wbr />coordinates(lat, lon)
#temperature in Kelvins
temp_K = weather['main']['temp']
#temperature in Fahrenheit
temp_F = (1.8 * (temp_K - 273)) + 32
Twitter.post_status("The current temperature is "+ str(temp_F) +"F")
Your Base Python module should look like this:
Click Save and Activate.
At 12:00 noon each day, you will receive a tweet to your twitter account (and on your phone if you set it up) with the current weather for Santa Clara, California.
Congratulations! You have successfully added twitter to your Medium One account!