def main(): api_key = "910f700cc0ff23ed2462312c250bc560" shared_secret = "b7be4d2a824b42b1" token = sys.argv[2] if len(sys.argv) == 3 else None task_name = sys.argv[1] api = Rtm(api_key, shared_secret, "delete", token) if not api.token_valid(): url, frob = api.authenticate_desktop() webbrowser.open(url) input("Continue?") # Get the token for the frob assert (api.retrieve_token(frob)) print("New token: {}".format(api.token)) result = api.rtm.timelines.create() timeline = result.timeline.value # Add task - default is Inbox result = api.rtm.tasks.add(timeline=timeline, parse="1", name=task_name) task_id = result.list.taskseries.id print("Create task, id: {}".format(task_id))
def index(request): context = {"DEBUG": settings.DEBUG} api = Rtm(settings.RTM_API_KEY, settings.RTM_API_SECRET, "read", None) if not api.token_valid(): # use desktop-type authentication auth_url, frob = api.authenticate_desktop() # open webbrowser, wait until user authorized application context['auth_url'] = auth_url context['auth_frob'] = frob return render(request, 'index.html', context=context)
def index(request): context = {"DEBUG": settings.DEBUG} api = Rtm(settings.RTM_API_KEY, settings.RTM_API_SECRET, "read", None) if not api.token_valid(): # use desktop-type authentication auth_url, frob = api.authenticate_desktop() # open webbrowser, wait until user authorized application context['auth_url'] = auth_url context['auth_frob'] = frob return render(request, 'index.html', context=context)
def _register_new_account( hass, account_name, api_key, shared_secret, stored_rtm_config, component ): request_id = None configurator = hass.components.configurator api = Rtm(api_key, shared_secret, "write", None) url, frob = api.authenticate_desktop() _LOGGER.debug("Sent authentication request to server") def register_account_callback(_): """Call for register the configurator.""" api.retrieve_token(frob) token = api.token if api.token is None: _LOGGER.error("Failed to register, please try again") configurator.notify_errors( request_id, "Failed to register, please try again." ) return stored_rtm_config.set_token(account_name, token) _LOGGER.debug("Retrieved new token from server") _create_instance( hass, account_name, api_key, shared_secret, token, stored_rtm_config, component, ) configurator.request_done(request_id) request_id = configurator.async_request_config( f"{DOMAIN} - {account_name}", callback=register_account_callback, description=( "You need to log in to Remember The Milk to" "connect your account. \n\n" "Step 1: Click on the link 'Remember The Milk login'\n\n" "Step 2: Click on 'login completed'" ), link_name="Remember The Milk login", link_url=url, submit_caption="login completed", )
def _register_new_account(hass, account_name, api_key, shared_secret, stored_rtm_config, component): from rtmapi import Rtm request_id = None configurator = hass.components.configurator api = Rtm(api_key, shared_secret, "write", None) url, frob = api.authenticate_desktop() _LOGGER.debug("Sent authentication request to server") def register_account_callback(_): """Call for register the configurator.""" api.retrieve_token(frob) token = api.token if api.token is None: _LOGGER.error("Failed to register, please try again") configurator.notify_errors( request_id, 'Failed to register, please try again.') return stored_rtm_config.set_token(account_name, token) _LOGGER.debug("Retrieved new token from server") _create_instance( hass, account_name, api_key, shared_secret, token, stored_rtm_config, component) configurator.request_done(request_id) request_id = configurator.async_request_config( '{} - {}'.format(DOMAIN, account_name), callback=register_account_callback, description='You need to log in to Remember The Milk to' + 'connect your account. \n\n' + 'Step 1: Click on the link "Remember The Milk login"\n\n' + 'Step 2: Click on "login completed"', link_name='Remember The Milk login', link_url=url, submit_caption="login completed", )
def _register_new_account(hass, account_name, api_key, shared_secret, stored_rtm_config, component, descriptions): from rtmapi import Rtm request_id = None configurator = hass.components.configurator api = Rtm(api_key, shared_secret, "write", None) url, frob = api.authenticate_desktop() _LOGGER.debug('sent authentication request to server') def register_account_callback(_): """Callback for configurator.""" api.retrieve_token(frob) token = api.token if api.token is None: _LOGGER.error('Failed to register, please try again.') configurator.notify_errors( request_id, 'Failed to register, please try again.') return stored_rtm_config.set_token(account_name, token) _LOGGER.debug('retrieved new token from server') _create_instance( hass, account_name, api_key, shared_secret, token, stored_rtm_config, component, descriptions) configurator.request_done(request_id) request_id = configurator.async_request_config( '{} - {}'.format(DOMAIN, account_name), callback=register_account_callback, description='You need to log in to Remember The Milk to' + 'connect your account. \n\n' + 'Step 1: Click on the link "Remember The Milk login"\n\n' + 'Step 2: Click on "login completed"', link_name='Remember The Milk login', link_url=url, submit_caption="login completed", )
import sys import webbrowser from rtmapi import Rtm if __name__ == '__main__': # call the program as `listtasks.py api_key shared_secret [optional: token]` # get those parameters from http://www.rememberthemilk.com/services/api/keys.rtm api_key, shared_secret = sys.argv[1:3] token = sys.argv[3] if len(sys.argv) >= 4 else None api = Rtm(api_key, shared_secret, "delete", token) # authenication block, see http://www.rememberthemilk.com/services/api/authentication.rtm # check for valid token if not api.token_valid(): # use desktop-type authentication url, frob = api.authenticate_desktop() # open webbrowser, wait until user authorized application webbrowser.open(url) raw_input("Continue?") # get the token for the frob api.retrieve_token(frob) # print out new token, should be used to initialize the Rtm object next time # (a real application should store the token somewhere) print "New token: %s" % api.token # get all open tasks, see http://www.rememberthemilk.com/services/api/methods/rtm.tasks.getList.rtm result = api.rtm.tasks.getList(filter="status:incomplete") for tasklist in result.tasks: for taskseries in tasklist: print taskseries.task.due, taskseries.name
def workhorse(): signal.signal(signal.SIGINT, quitter) # put the api token and secret in the credentials file (chmod 600) # get those parameters from http://www.rememberthemilk.com/services/api/keys.rtm debug = True if (len(sys.argv) > 1 and sys.argv[1] == 'debug') else False colourtest = True if (len(sys.argv) > 1 and sys.argv[1] == 'colourtest') else False config = configparser.ConfigParser() # test for file presence # if not there, exit telling user to rename template to file and get api key ## TODO: implement previous comment config.read_file(open('rtmstatus.conf')) # test for config items existing if (not config.has_option('main', 'api_key') or not config.has_option('main', 'shared_secret')): # without api_key or shared_secret, I cannot do anything, so exit and tell user to get an API key print ('You need to get a RTM API key and shared secret to use this script.') # exiting with an error code because the script cannot run sys.exit(1) # if token isn't there then launch API without it so we can get one and store it, else launch anyway. if config.has_option('main','token'): api = Rtm(config.get('main', 'api_key'), config.get('main', 'shared_secret'), 'read', config.get('main', 'token')) else: api = Rtm(config.get('main', 'api_key'), config.get('main', 'shared_secret'), 'read', None) # authentication block, see http://www.rememberthemilk.com/services/api/authentication.rtm # check for valid token if not api.token_valid(): # use desktop-type authentication url, frob = api.authenticate_desktop() # open webbrowser, wait until user authorized application webbrowser.open(url) input("Continue?") # get the token for the frob api.retrieve_token(frob) # If the token turns out to be invalid, we get a valid one and store it. config.set('main','token',api.token) with open('rtmstatus.conf', 'w') as configfile: config.write(configfile) # TODO test that this worked # reinitialize the Rtm object del api api = Rtm(config.get('main', 'api_key'), config.get('main', 'shared_secret'), 'read', config.get('main', 'token')) display.connect() display.display_on() print('Press Ctrl+C to quit') while True: backlight = config.get('main', 'defaultcolour') count = {} sections = config.sections() sections.sort(reverse=True) for section in sections: if section != 'main': count[section] = taskcounter(config.get(section, 'filter'), api) display.clear() for section in sections: if section != 'main': display.set_cursor_position(int(config.get(section,'x')),int(config.get(section,'y'))) if int(count[section]) < 10: display.write(config.get(section,'label') + ': ' + str(count[section])) else: display.write(config.get(section,'label') + ':' + str(count[section])) if (int(count[section]) > int(config.get(section,'threshold'))): backlight = config.get(section, 'colour') rgb = backlight.split(',') display.set_backlight_rgb(int(rgb[0]),int(rgb[1]),int(rgb[2])) time.sleep(float(config.get('main','polling_delay')))
# MIT license. from __future__ import print_function import rtm_const import sys import webbrowser from rtmapi import Rtm from Adafruit_Thermal import * if __name__ == '__main__': api = Rtm(rtm_const.api_key, rtm_const.shared_secret, "read", rtm_const.token) # authenication block, see http://www.rememberthemilk.com/services/api/authentication.rtm # check for valid token if not api.token_valid(): # use desktop-type authentication url, frob = api.authenticate_desktop() # open webbrowser, wait until user authorized application print ("URL you need to open: %s" % url) webbrowser.open(url) raw_input("Continue?") # get the token for the frob api.retrieve_token(frob) # print out new token, should be used to initialize the Rtm object next time print ("token: %s" % api.token) f1=open('./rtm_const', 'w+') f1.write("token: %s\n" % api.token) print ("You're going to need to remove the duplicate token line\n") f1.close printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
def main(raw_args=None): # Check the arguments passed to this script parser = argparse.ArgumentParser( description='Get a random TO DO from Remember the Milk!', prefix_chars='-/', epilog= 'Note that multiple flags are ANDed together making your search more specific. See docs for more info.' ) parser.add_argument('--loglevel', dest='loglevel', metavar='', choices=['debug'], type=str.lower, help="[optional] Set the log level (e.g. debug, etc.)") parser.add_argument( '-l', '--list', metavar='', help= "[optional] Select a specific list to search in. Use quotes if your list name has spaces in it." ) parser.add_argument( '-t', '--tag', metavar='', help="[optional] Select a specific tag to add to your search filter.") parser.add_argument( '-p', '--priority', metavar='', choices=['1', '2', '3', 'N'], help= "[optional] Select a specific priority to add to your search filter.") args = parser.parse_args(raw_args) # Set loglevel if --loglevel argument is used, otherwise set to INFO if args.loglevel is None: logging_num_level = 20 else: logging_num_level = getattr(logging, args.loglevel.upper()) LOG_FORMAT = "\n %(levelname)s: %(message)s" logging.basicConfig(level=logging_num_level, format=LOG_FORMAT) logging.debug("Args passed in are: " + str(args)) rtm_list = args.list rtm_tag = args.tag rtm_priority = args.priority # Look for a token in ~/.rtm_auth_token first user_home_dir = os.path.expanduser("~") rtm_auth_file = os.path.join(user_home_dir, '.rtm_auth_token') if os.path.exists(rtm_auth_file): with open(rtm_auth_file, "r") as f: token = f.readline() else: token = None # Create a class instance using the RtmAPI module api = Rtm(api_key, shared_secret, "read", token, api_version=2) # Authenication block, see http://www.rememberthemilk.com/services/api/authentication.rtm # Check for valid token. If none, open a browser so the user can authenticate. if not api.token_valid(): # use desktop-type authentication url, frob = api.authenticate_desktop() # open webbrowser, wait until user authorized application webbrowser.open(url) raw_input("Continue?") # get the token for the frob api.retrieve_token(frob) # print out new token, should be used to initialize the Rtm object next time # (a real application should store the token somewhere) logging.debug("New token: %s" % api.token) # Write out the token to the user's home directory f = open(rtm_auth_file, "w") f.write(api.token) f.close() # Get all incomplete tasks based on the constructed filter. # RTM filters: https://www.rememberthemilk.com/help/?ctx=basics.search.advanced filter = 'status:incomplete isSubtask:false' if rtm_list: filter = filter + ' list:"%s"' % rtm_list if rtm_tag: filter = filter + ' tag:"%s"' % rtm_tag if rtm_priority: filter = filter + ' priority:"%s"' % rtm_priority logging.debug("filter is now: " + filter) result = api.rtm.tasks.getList(filter="%s" % filter) list_of_tasks = [] # Use the RtmAPI tasks iter to put the filtered set of tasks into a list for tasklist in result.tasks: for taskseries in tasklist: list_of_tasks.append(taskseries.name) # If the total # of retrieved tasks is zero, print mesg & exit if not list_of_tasks: print "\n\tSorry, but your filter didn't find any to dos." print "\tPerhaps re-check your spelling and try again.\n" exit(0) # Pick out a random task name random_task_name = random.choice(list_of_tasks) logging.debug("Random task name is: " + random_task_name) # Use the random task's name to retrieve its full info result = "" result = api.rtm.tasks.getList(filter='name:"%s"' % random_task_name) logging.debug("results.tasks has a type of: " + str(type(result.tasks))) # Use the RtmAPI iterators to drill down to the taskseries & task info. # To better understand what's going on here, you'll need to read the # RtmAPI docs as well as how Remember The Milk's API returns queries. first_tasklist = iter(result.tasks).next() logging.debug("tasklist has a type of: " + str(type(tasklist))) first_taskseries = iter(first_tasklist).next() logging.debug("first_taskseries type is: " + str(type(first_taskseries))) spinner() # Cosmetic only ;-) print "\nTask Name: \t", COLORAMA_STYLE, COLORAMA_BG, COLORAMA_FG, first_taskseries.name, Style.RESET_ALL if "N" in first_taskseries.task.priority: print 'Priority: \t', COLORAMA_STYLE, COLORAMA_BG, COLORAMA_FG, 'None', Style.RESET_ALL else: print 'Priority: \t', COLORAMA_STYLE, COLORAMA_BG, COLORAMA_FG, first_taskseries.task.priority, Style.RESET_ALL if first_taskseries.task.due == '': print 'Due: \t\t -' else: formatted_date = strftime( strptime(first_taskseries.task.due, "%Y-%m-%dT%H:%M:%SZ"), "%d %b %Y") print 'Due: \t\t', COLORAMA_STYLE, COLORAMA_BG, COLORAMA_FG, formatted_date, Style.RESET_ALL # As a bonus, print the # of tasks in the user's search filter print "\nPS: The total # of tasks with your search filter is: ", COLORAMA_STYLE, \ COLORAMA_BG, COLORAMA_FG, len(list_of_tasks), Style.RESET_ALL, "\n"