PEP8 compatibility
This commit is contained in:
parent
9982477759
commit
420c9a783c
1 changed files with 129 additions and 129 deletions
|
@ -1,147 +1,147 @@
|
||||||
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()
|
||||||
|
|
||||||
def get_all_possible_timezones_of_local_machine(self):
|
def get_all_possible_timezones_of_local_machine(self):
|
||||||
"""
|
"""
|
||||||
Return all possible timezones in Olson TZ notation
|
Return all possible timezones in Olson TZ notation
|
||||||
This has been taken from
|
This has been taken from
|
||||||
http://stackoverflow.com/questions/7669938
|
http://stackoverflow.com/questions/7669938
|
||||||
"""
|
"""
|
||||||
local_names = []
|
local_names = []
|
||||||
if time.daylight:
|
if time.daylight:
|
||||||
local_offset = time.altzone
|
local_offset = time.altzone
|
||||||
localtz = time.tzname[1]
|
localtz = time.tzname[1]
|
||||||
else:
|
else:
|
||||||
local_offset = time.timezone
|
local_offset = time.timezone
|
||||||
localtz = time.tzname[0]
|
localtz = time.tzname[0]
|
||||||
|
|
||||||
local_offset = timedelta(seconds=-local_offset)
|
local_offset = timedelta(seconds=-local_offset)
|
||||||
|
|
||||||
for name in pytz.all_timezones:
|
for name in pytz.all_timezones:
|
||||||
timezone = pytz.timezone(name)
|
timezone = pytz.timezone(name)
|
||||||
if not hasattr(timezone, '_tzinfos'):
|
if not hasattr(timezone, '_tzinfos'):
|
||||||
continue
|
continue
|
||||||
for (utcoffset, daylight, tzname), _ in timezone._tzinfos.items():
|
for (utcoffset, daylight, tzname), _ in timezone._tzinfos.items():
|
||||||
if utcoffset == local_offset and tzname == localtz:
|
if utcoffset == local_offset and tzname == localtz:
|
||||||
local_names.append(name)
|
local_names.append(name)
|
||||||
return local_names
|
return local_names
|
||||||
|
|
||||||
|
def get_system_tz(self):
|
||||||
|
"""
|
||||||
|
Retrieves the system's timezone from a list of possible options.
|
||||||
|
Just take the first one
|
||||||
|
"""
|
||||||
|
return self.get_all_possible_timezones_of_local_machine()[0]
|
||||||
|
|
||||||
|
def refresh(self):
|
||||||
|
host = self._service_root.split('//')[1].split(':')[0]
|
||||||
|
self.session.headers.update({'host': host})
|
||||||
|
|
||||||
def get_system_tz(self):
|
params_reminders = dict(self.params)
|
||||||
"""
|
params_reminders.update({
|
||||||
Retrieves the system's timezone from a list of possible options.
|
'clientVersion': '4.0',
|
||||||
Just take the first one
|
'lang': 'en-us',
|
||||||
"""
|
'usertz': self.get_system_tz()
|
||||||
return self.get_all_possible_timezones_of_local_machine()[0]
|
})
|
||||||
|
|
||||||
|
# Open reminders
|
||||||
|
req = self.session.get(
|
||||||
|
self._service_root + '/rd/startup',
|
||||||
|
params=params_reminders
|
||||||
|
)
|
||||||
|
|
||||||
|
startup = req.json()
|
||||||
|
|
||||||
def refresh(self):
|
self.lists = {}
|
||||||
host = self._service_root.split('//')[1].split(':')[0]
|
self.collections = {}
|
||||||
self.session.headers.update({'host': host})
|
for collection in startup['Collections']:
|
||||||
|
temp = []
|
||||||
|
self.collections[collection['title']] = {
|
||||||
|
'guid': collection['guid'],
|
||||||
|
'ctag': collection['ctag']
|
||||||
|
}
|
||||||
|
for reminder in startup['Reminders']:
|
||||||
|
|
||||||
params_reminders=dict(self.params)
|
if reminder['pGuid'] != collection['guid']:
|
||||||
params_reminders.update({
|
continue
|
||||||
'clientVersion': '4.0',
|
if 'dueDate' in reminder:
|
||||||
'lang': 'en-us',
|
if reminder['dueDate']:
|
||||||
'usertz':self.get_system_tz()
|
due = datetime(
|
||||||
})
|
reminder['dueDate'][1],
|
||||||
|
reminder['dueDate'][2], reminder['dueDate'][3],
|
||||||
|
reminder['dueDate'][4], reminder['dueDate'][5]
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
due = None
|
||||||
|
else:
|
||||||
|
due = None
|
||||||
|
if reminder['description']:
|
||||||
|
desc = reminder['description']
|
||||||
|
else:
|
||||||
|
desc = ""
|
||||||
|
temp.append({
|
||||||
|
"title": reminder['title'],
|
||||||
|
"desc": desc,
|
||||||
|
"due": due
|
||||||
|
})
|
||||||
|
self.lists[collection['title']] = temp
|
||||||
|
|
||||||
# Open reminders
|
def post(self, title, description="", collection=None):
|
||||||
req = self.session.get(
|
pguid = 'tasks'
|
||||||
self._service_root + '/rd/startup',
|
if collection:
|
||||||
params=params_reminders
|
if collection in self.collections:
|
||||||
)
|
pguid = self.collections[collection]['guid']
|
||||||
|
|
||||||
startup = req.json()
|
host = self._service_root.split('//')[1].split(':')[0]
|
||||||
|
self.session.headers.update({'host': host})
|
||||||
|
|
||||||
self.lists={}
|
params_reminders = dict(self.params)
|
||||||
self.collections = {}
|
params_reminders.update({
|
||||||
for collection in startup['Collections']:
|
'clientVersion': '4.0',
|
||||||
temp = []
|
'lang': 'en-us',
|
||||||
self.collections[collection['title']] = {
|
'usertz': self.get_system_tz()
|
||||||
'guid': collection['guid'],
|
})
|
||||||
'ctag': collection['ctag']
|
|
||||||
}
|
|
||||||
for reminder in startup['Reminders']:
|
|
||||||
|
|
||||||
if reminder['pGuid'] != collection['guid']:
|
req = self.session.post(
|
||||||
continue
|
self._service_root + '/rd/reminders/tasks',
|
||||||
if reminder.has_key("dueDate"):
|
data=json.dumps({
|
||||||
if reminder['dueDate']:
|
"Reminders": {
|
||||||
due = datetime(
|
'title': title,
|
||||||
reminder['dueDate'][1],
|
"description": description,
|
||||||
reminder['dueDate'][2],reminder['dueDate'][3],
|
"pGuid": pguid,
|
||||||
reminder['dueDate'][4],reminder['dueDate'][5]
|
"etag": None,
|
||||||
)
|
"order": None,
|
||||||
else:
|
"priority": 0,
|
||||||
due = None
|
"recurrence": None,
|
||||||
else:
|
"alarms": [],
|
||||||
due = None
|
"startDate": None,
|
||||||
desc=reminder['description'] if reminder['description'] else ""
|
"startDateTz": None,
|
||||||
temp.append({
|
"startDateIsAllDay": False,
|
||||||
"title": reminder['title'],
|
"completedDate": None,
|
||||||
"desc": desc,
|
"dueDate": None,
|
||||||
"due": due
|
"dueDateIsAllDay": False,
|
||||||
})
|
"lastModifiedDate": None,
|
||||||
self.lists[collection['title']] = temp
|
"createdDate": None,
|
||||||
|
"isFamily": None,
|
||||||
def post(self, title, description = "", collection=None):
|
"createdDateExtended": int(time.time()*1000),
|
||||||
pguid = 'tasks'
|
"guid": str(uuid.uuid4())
|
||||||
if collection:
|
},
|
||||||
if self.collections.has_key(collection):
|
"ClientState": {"Collections": self.collections.values()}
|
||||||
pguid = self.collections[collection]['guid']
|
}),
|
||||||
|
params=params_reminders)
|
||||||
host = self._service_root.split('//')[1].split(':')[0]
|
return req.ok
|
||||||
self.session.headers.update({'host': host})
|
|
||||||
|
|
||||||
params_reminders=dict(self.params)
|
|
||||||
params_reminders.update({
|
|
||||||
'clientVersion': '4.0',
|
|
||||||
'lang': 'en-us',
|
|
||||||
'usertz':self.get_system_tz()
|
|
||||||
})
|
|
||||||
|
|
||||||
req = self.session.post(
|
|
||||||
self._service_root + '/rd/reminders/tasks',
|
|
||||||
data=json.dumps({
|
|
||||||
"Reminders":{
|
|
||||||
'title': title,
|
|
||||||
"description":description,
|
|
||||||
"pGuid":pguid,
|
|
||||||
"etag":None,
|
|
||||||
"order":None,
|
|
||||||
"priority":0,
|
|
||||||
"recurrence":None,
|
|
||||||
"alarms":[],
|
|
||||||
"startDate":None,
|
|
||||||
"startDateTz":None,
|
|
||||||
"startDateIsAllDay":False,
|
|
||||||
"completedDate":None,
|
|
||||||
"dueDate":None,
|
|
||||||
"dueDateIsAllDay":False,
|
|
||||||
"lastModifiedDate":None,
|
|
||||||
"createdDate":None,
|
|
||||||
"isFamily":None,
|
|
||||||
"createdDateExtended":int(time.time()*1000),
|
|
||||||
"guid":str(uuid.uuid4())
|
|
||||||
},
|
|
||||||
"ClientState": {"Collections": self.collections.values() }
|
|
||||||
}),
|
|
||||||
params=params_reminders)
|
|
||||||
|
|
Loading…
Reference in a new issue