#!/usr/bin/python
# -*- coding: utf-8 -*-
import time
import pycurl, json
import Timetable
import todoist
import Sensitive

from io import BytesIO as StringIO
app_ID = Sensitive.app_ID
app_secret = Sensitive.app_secret
pushEvent = "message"
pushMessage = "first"
buffer = StringIO()
c = pycurl.Curl() 
c.setopt(c.URL, 'https://api.instapush.im/v1/post')
c.setopt(c.HTTPHEADER, ['x-instapush-appid: ' + app_ID,
'x-instapush-appsecret: ' + app_secret,
'Content-Type: application/json'])

# create a dictionary structure for the JSON data to post to Instapush
json_fields = {}

# setup JSON values
json_fields['event']=pushEvent
json_fields['trackers'] = {}
json_fields['trackers']['message']=pushMessage

postfields = json.dumps(json_fields)

# make sure to send the JSON with post
c.setopt(c.POSTFIELDS, postfields)

# set this so we can capture the resposne in our buffer
c.setopt(c.WRITEFUNCTION, buffer.write)

# uncomment to see the post that is sent
#c.setopt(c.VERBOSE, True)
def change_push_message(pushMessage):
	json_fields['trackers']['message']=pushMessage
	postfields = json.dumps(json_fields)
	c.setopt(c.POSTFIELDS, postfields)


# setup an indefinite loop that looks for the door to be opened / closed
def main():
	while True:
		body= buffer.getvalue()
		# reset the buffer
		buffer.truncate(0)
		buffer.seek(0)
		time.sleep(15)
		
	c.close()

if __name__ == '__main__':
	main()

@@ -479,16 +479,189 @@
 son'%5D)%0A%0A
+#todoist%0Aapi = todoist.TodoistAPI()%0Auser = api.login(Sensitive.e_mail, Sensitive.password)%0A#response = api.sync(recource_types = %5B'all'%5D)%0ApushMessage = user%5B'full_name'%5D%0A%0A%0A%0A
 # create
@@ -723,16 +723,16 @@
 stapush%0A
-
 json_fie
@@ -1308,16 +1308,539 @@
 ields)%0A%0A
+def do_what_user_wants():%0A%09user = api.login(Sensitive.e_mail, Sensitive.password)%0A%09input_str = user%5B'full_name'%5D%0A%09input_tokens = input_str.split()%0A%09if input_tokens%5B0%5D == 'bus':%0A%09%09pushMessage = ''%0A%09%09start = %22CasparDavidFriedrichStra%C3%9Fe%22 # default value%0A%09%09if len(input_tokens) %3E 1:%0A%09%09%09start = input_tokens%5B1%5D%0A%09%09rides = Timetable.get_buses(start)%09%0A%09%09for ride in rides:%0A%09%09%09pushMessage += %22%7Bline%7D: %7Btime%7DMin, %22.format(line = ride%5B0%5D, time = ride%5B2%5D)%0A%09%09change_push_message(pushMessage)%0A%09%09c.perform()%0A%09%09print(%22Message sent!%5Cn%22)%0A%09%09%0A
 %0A# setup
@@ -1930,16 +1930,16 @@
 e True:%0A
-
 %09%09body= 
@@ -1956,16 +1956,60 @@
 value()%0A
+%09%09do_what_user_wants() # look for username %0A
 %09%09# rese

add Todoist API to program