8000 uses strptime for date and time · jjjchens235/python-api-client@48810c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 48810c8

Browse files
Matthew Leon GrinshpunNathan Hamblen
authored andcommitted
uses strptime for date and time
1 parent de79e20 commit 48810c8

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

‎meetup_api_client.py

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env python
22
from __future__ import with_statement
33

4-
import datetime
54
import time
65
import types
76
from urllib import urlencode
87
from urllib2 import HTTPError, HTTPErrorProcessor, urlopen, Request, build_opener
8+
from datetime import datetime
99

1010
import oauth
1111
import MultipartPostHandler as mph
@@ -231,21 +231,31 @@ def __init__(self, json, uritype):
231231
def __str__(self):
232232
return 'meta: ' + str(self.meta) + '\n' + str(self.results)
233233

234+
def converttime(str):
235+
"""Given a time string in Meetup's format, return a datetime."""
236+
MEETUP_DATE_FORMAT = '%a %b %d %H:%M:%S %Z %Y'
237+
return datetime.strptime(str, MEETUP_DATE_FORMAT)
238+
234239
class API_Item(object):
235240
"""Base class for an item in a result set returned by the API."""
236241

237242
datafields = [] #override
243+
timefields = [] #override
238244
def __init__(self, properties):
239-
"""load properties that are relevant to all items (id, etc.)"""
240-
for field in self.datafields:
241-
self.__setattr__(field, properties[field])
242-
self.json = properties
245+
"""load properties that are relevant to all items (id, etc.)"""
246+
for field in self.datafields:
247+
self.__setattr__(field, properties[field])
248+
for field in self.timefields:
249+
self.__setattr__(field, converttime(properties[field]))
250+
self.json = properties
243251

244252
def __repr__(self):
245253
return self.__str__();
246254

247255
class Member(API_Item):
248-
datafields = ['bio', 'name', 'link','id','photo_url', 'zip','lat','lon','city','state','country','joined','visited']
256+
datafields = ['bio', 'name', 'link','id','photo_url', 'zip','lat','lon',
257+
'city','state','country']
258+
timefields = ['joined', 'visited']
249259

250260
def get_groups(self, apiclient, **extraparams):
251261
extraparams.update({'member_id':self.id})
@@ -255,14 +265,19 @@ def __str__(self):
255265
return "Member %s (url: %s)" % (self.name, self.link)
256266

257267
class Photo(API_Item):
258-
datafields = ['albumtitle', 'link', 'member_url', 'descr', 'created', 'photo_url', 'photo_urls', 'thumb_urls']
268+
datafields = ['albumtitle', 'link', 'member_url', 'descr', 'photo_url',
269+
'photo_urls', 'thumb_urls']
270+
timefields = ['created']
259271

260272
def __str__(self):
261273
return "Photo located at %s posted by member at %s: (%s)" % (self.link, self.member_url, self.descr)
262274

263275

264276
class Event(API_Item):
265-
datafields = ['id', 'name', 'updated', 'time', 'photo_url', 'event_url', 'venue_lat', 'venue_lon', 'description', 'status', 'rsvpcount', 'no_rsvpcount', 'maybe_rsvpcount']
277+
datafields = ['id', 'name', 'photo_url', 'event_url', 'venue_lat',
278+
'venue_lon', 'description', 'status', 'rsvpcount',
279+
'no_rsvpcount', 'maybe_rsvpcount']
280+
timefields = ['time', 'updated']
266281

267282
def __str__(self):
268283
return 'Event %s named %s at %s (url: %s)' % (self.id, self.name, self.time, self.event_url)
@@ -272,17 +287,18 @@ def get_rsvps(self, apiclient, **extraparams):
272287
return apiclient.get_rsvps(**extraparams)
273288

274289
class Rsvp(API_Item):
275-
datafields = ['name', 'link', 'comment','zip','coord','lon','city','state','country','response','guests','answers','updated','created']
290+
datafields = ['name', 'link', 'comment','zip','coord','lon','city','state',
291+
'country','response','guests','answers']
292+
timefields = ['updated', 'created']
276293

277294
def __str__(self):
278295
return 'Rsvp by %s (%s) with comment: %s' % (self.name, self.link, self.comment)
279296

280297
class Group(API_Item):
281-
datafields = [ 'id','name','group_urlname','link','updated',\
282-
'members','created','photo_url',\
283-
'description','zip','lat','lon',\
284-
'city','state','country','organizerProfileURL', \
285-
'topics']
298+
datafields = [ 'id','name','group_urlname','link', 'members','photo_url',
299+
'description','zip','lat','lon', 'city','state','country',
300+
'organizerProfileURL', 'topics']
301+
timefields = ['created', 'updated']
286302

287303
def __str__(self):
288304
return "%s (%s)" % (self.name, self.link)
@@ -316,8 +332,8 @@ def get_events(self,apiclient, **extraparams):
316332
return apiclient.get_events(**extraparams)
317333

318334
class Topic(API_Item):
319-
datafields = ['id','name','description','link','updated',\
320-
'members','urlkey']
335+
datafields = ['id','name','description','link', 'members','urlkey']
336+
timefields = ['updated']
321337

322338
def __str__(self):
323339
return "%s with %s members (%s)" % (self.name, self.members,
@@ -332,8 +348,9 @@ def get_photos(self, apiclient, **extraparams):
332348
return apiclient.get_photos(**extraparams)
333349

334350
class Comment(API_Item):
335-
datafields = ['name','link','comment','rating','photo_url',\
336-
'created','lat','lon','country','city','state']
351+
datafields = ['name','link','comment','rating','photo_url',
352+
'lat','lon','country','city','state']
353+
timefields = ['created']
337354

338355
def __str__(self):
339356
return "Comment from %s (%s)" % (self.name, self.link)

0 commit comments

Comments
 (0)
0