Links

Schedule posts

Tags: #twitter #automation #ifttt #naas_drivers #gsheet #content
Author: Jeremy Ravenel​
Description: This notebook allows you to plan and schedule posts to your Twitter account.

Input

Import library

from datetime import datetime
import naas_drivers
import naas

Variables

spreadsheet_id = "1rFzw8eeVNXyD5CEUjnpxVn_iA2hzabYKU6pRdmnZ3FQ"

Model

Get data from Gsheet

df = naas_drivers.gsheet.connect(spreadsheet_id).get(sheet_name="Sheet1")
df

Get current date and time details

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

Schedule check every minute

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

Output

If current date and column date in Gsheet matches then post

for i in range(len(df)):
print(dt_string, df["BROADCAST_DATE"][i])
if dt_string == df["BROADCAST_DATE"][i]:
twitter_post = df["TEXT"][i]
event = "naas_demo"
key = "ke4AigvXI5-EABaowdLt4fju1aOUxeMxSXQoN8FVyA"
data = {"value1": twitter_post}
result = naas_drivers.ifttt.connect(key).send(event, data)