Schedule posts
Tags: #twitter #automation #ifttt #naas_drivers #gsheet
Author: Jeremy Ravenel

Input

Import library

1
from datetime import datetime
2
import naas_drivers
3
import naas
Copied!

Variables

1
spreadsheet_id = "1rFzw8eeVNXyD5CEUjnpxVn_iA2hzabYKU6pRdmnZ3FQ"
Copied!

Model

Get data from Gsheet

1
df = naas_drivers.gsheet.connect(spreadsheet_id).get(
2
sheet_name="Sheet1"
3
)
4
df
Copied!

Get current date and time details

1
now = datetime.now().replace(second=0, microsecond=0) #the Naas scheduler only allow minutes
2
now
Copied!
1
# dd/mm/YY H:M:S
2
dt_string = now.strftime("%d/%m/%Y %H:%M:%S") # To mach date time format in google sheet
3
dt_string
Copied!

Schedule check every minute

If BROADCAST_DATE matches the current time then send twit from text column.
1
#naas.scheduler.delete()
2
naas.scheduler.add(recurrence="* * * * *") # to run every minute
Copied!

Output

If current date and column date in Gsheet matches then post

1
for i in range(len(df)):
2
print(dt_string, df['BROADCAST_DATE'][i])
3
if dt_string == df['BROADCAST_DATE'][i]:
4
twitter_post = df['TEXT'][i]
5
event = "naas_demo"
6
key = "ke4AigvXI5-EABaowdLt4fju1aOUxeMxSXQoN8FVyA"
7
data = { "value1": twitter_post }
8
result = naas_drivers.ifttt.connect(key).send(event, data)
Copied!
Copy link
Edit on GitHub