PEP8 compatibility
This commit is contained in:
parent
9982477759
commit
420c9a783c
1 changed files with 129 additions and 129 deletions
|
@ -1,17 +1,17 @@
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from calendar import monthrange
|
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
import pytz
|
import pytz
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
class RemindersService(object):
|
class RemindersService(object):
|
||||||
def __init__(self, service_root, session, params):
|
def __init__(self, service_root, session, params):
|
||||||
self.session = session
|
self.session = session
|
||||||
self.params = params
|
self.params = params
|
||||||
self._service_root = service_root
|
self._service_root = service_root
|
||||||
self.lists={}
|
self.lists = {}
|
||||||
self.collections = {}
|
self.collections = {}
|
||||||
|
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
@ -41,8 +41,6 @@ class RemindersService(object):
|
||||||
local_names.append(name)
|
local_names.append(name)
|
||||||
return local_names
|
return local_names
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_system_tz(self):
|
def get_system_tz(self):
|
||||||
"""
|
"""
|
||||||
Retrieves the system's timezone from a list of possible options.
|
Retrieves the system's timezone from a list of possible options.
|
||||||
|
@ -50,17 +48,15 @@ class RemindersService(object):
|
||||||
"""
|
"""
|
||||||
return self.get_all_possible_timezones_of_local_machine()[0]
|
return self.get_all_possible_timezones_of_local_machine()[0]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
host = self._service_root.split('//')[1].split(':')[0]
|
host = self._service_root.split('//')[1].split(':')[0]
|
||||||
self.session.headers.update({'host': host})
|
self.session.headers.update({'host': host})
|
||||||
|
|
||||||
params_reminders=dict(self.params)
|
params_reminders = dict(self.params)
|
||||||
params_reminders.update({
|
params_reminders.update({
|
||||||
'clientVersion': '4.0',
|
'clientVersion': '4.0',
|
||||||
'lang': 'en-us',
|
'lang': 'en-us',
|
||||||
'usertz':self.get_system_tz()
|
'usertz': self.get_system_tz()
|
||||||
})
|
})
|
||||||
|
|
||||||
# Open reminders
|
# Open reminders
|
||||||
|
@ -71,7 +67,7 @@ class RemindersService(object):
|
||||||
|
|
||||||
startup = req.json()
|
startup = req.json()
|
||||||
|
|
||||||
self.lists={}
|
self.lists = {}
|
||||||
self.collections = {}
|
self.collections = {}
|
||||||
for collection in startup['Collections']:
|
for collection in startup['Collections']:
|
||||||
temp = []
|
temp = []
|
||||||
|
@ -83,18 +79,21 @@ class RemindersService(object):
|
||||||
|
|
||||||
if reminder['pGuid'] != collection['guid']:
|
if reminder['pGuid'] != collection['guid']:
|
||||||
continue
|
continue
|
||||||
if reminder.has_key("dueDate"):
|
if 'dueDate' in reminder:
|
||||||
if reminder['dueDate']:
|
if reminder['dueDate']:
|
||||||
due = datetime(
|
due = datetime(
|
||||||
reminder['dueDate'][1],
|
reminder['dueDate'][1],
|
||||||
reminder['dueDate'][2],reminder['dueDate'][3],
|
reminder['dueDate'][2], reminder['dueDate'][3],
|
||||||
reminder['dueDate'][4],reminder['dueDate'][5]
|
reminder['dueDate'][4], reminder['dueDate'][5]
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
due = None
|
due = None
|
||||||
else:
|
else:
|
||||||
due = None
|
due = None
|
||||||
desc=reminder['description'] if reminder['description'] else ""
|
if reminder['description']:
|
||||||
|
desc = reminder['description']
|
||||||
|
else:
|
||||||
|
desc = ""
|
||||||
temp.append({
|
temp.append({
|
||||||
"title": reminder['title'],
|
"title": reminder['title'],
|
||||||
"desc": desc,
|
"desc": desc,
|
||||||
|
@ -102,46 +101,47 @@ class RemindersService(object):
|
||||||
})
|
})
|
||||||
self.lists[collection['title']] = temp
|
self.lists[collection['title']] = temp
|
||||||
|
|
||||||
def post(self, title, description = "", collection=None):
|
def post(self, title, description="", collection=None):
|
||||||
pguid = 'tasks'
|
pguid = 'tasks'
|
||||||
if collection:
|
if collection:
|
||||||
if self.collections.has_key(collection):
|
if collection in self.collections:
|
||||||
pguid = self.collections[collection]['guid']
|
pguid = self.collections[collection]['guid']
|
||||||
|
|
||||||
host = self._service_root.split('//')[1].split(':')[0]
|
host = self._service_root.split('//')[1].split(':')[0]
|
||||||
self.session.headers.update({'host': host})
|
self.session.headers.update({'host': host})
|
||||||
|
|
||||||
params_reminders=dict(self.params)
|
params_reminders = dict(self.params)
|
||||||
params_reminders.update({
|
params_reminders.update({
|
||||||
'clientVersion': '4.0',
|
'clientVersion': '4.0',
|
||||||
'lang': 'en-us',
|
'lang': 'en-us',
|
||||||
'usertz':self.get_system_tz()
|
'usertz': self.get_system_tz()
|
||||||
})
|
})
|
||||||
|
|
||||||
req = self.session.post(
|
req = self.session.post(
|
||||||
self._service_root + '/rd/reminders/tasks',
|
self._service_root + '/rd/reminders/tasks',
|
||||||
data=json.dumps({
|
data=json.dumps({
|
||||||
"Reminders":{
|
"Reminders": {
|
||||||
'title': title,
|
'title': title,
|
||||||
"description":description,
|
"description": description,
|
||||||
"pGuid":pguid,
|
"pGuid": pguid,
|
||||||
"etag":None,
|
"etag": None,
|
||||||
"order":None,
|
"order": None,
|
||||||
"priority":0,
|
"priority": 0,
|
||||||
"recurrence":None,
|
"recurrence": None,
|
||||||
"alarms":[],
|
"alarms": [],
|
||||||
"startDate":None,
|
"startDate": None,
|
||||||
"startDateTz":None,
|
"startDateTz": None,
|
||||||
"startDateIsAllDay":False,
|
"startDateIsAllDay": False,
|
||||||
"completedDate":None,
|
"completedDate": None,
|
||||||
"dueDate":None,
|
"dueDate": None,
|
||||||
"dueDateIsAllDay":False,
|
"dueDateIsAllDay": False,
|
||||||
"lastModifiedDate":None,
|
"lastModifiedDate": None,
|
||||||
"createdDate":None,
|
"createdDate": None,
|
||||||
"isFamily":None,
|
"isFamily": None,
|
||||||
"createdDateExtended":int(time.time()*1000),
|
"createdDateExtended": int(time.time()*1000),
|
||||||
"guid":str(uuid.uuid4())
|
"guid": str(uuid.uuid4())
|
||||||
},
|
},
|
||||||
"ClientState": {"Collections": self.collections.values() }
|
"ClientState": {"Collections": self.collections.values()}
|
||||||
}),
|
}),
|
||||||
params=params_reminders)
|
params=params_reminders)
|
||||||
|
return req.ok
|
||||||
|
|
Loading…
Reference in a new issue