This commit is contained in:
Kenneth Reitz
2011-02-19 20:10:17 -05:00
parent 1b75b13b21
commit 0bfb6b13f9
2 changed files with 52 additions and 30 deletions
+22 -30
View File
@@ -1,6 +1,5 @@
import json
from datetime import datetime
from collections import MutableSequence
import requests
@@ -132,61 +131,56 @@ class Group(object):
class Groups(object):
def __init__(self):
self.data = []
self.groups = []
self.sync()
def joined(self):
"""Returns list of Joined groups."""
return [g for g in self.data if g.joined]
return [g for g in self.groups if g.joined]
def __repr__(self):
return str(self.data)
return str(self.groups)
def __getitem__(self, key):
if isinstance(key, int):
key = str(key)
for group in self.groups:
for group in self.data:
if key in (group.id, group.slug):
if str(key) in [group.id, group.slug]:
return group
else:
print (key, group.id)
r = get('groups', key)
group = Group()
group.import_from_api(json.loads(r.content)['group'])
# self.data.append(group)
self.data = []
return group
_group = Group()
_group.import_from_api(json.loads(r.content)['group'])
print len(self.groups)
self.groups.append(_group)
print '%s appended!' % (_group)
print len(self.groups)
return _group
def __iter__(self):
for group in self.groups:
yield group
def __contains__(self, key):
if isinstance(key, int):
key = unicode(key)
for group in self.data:
if key in (group.id, group.slug):
for group in self.groups:
if key in [group.id, group.slug]:
return True
return False
def __iter__(self):
for group in self.data:
yield group
def sync(self):
self.data = []
self.groups = []
r = requests.get(API_URL + 'groups.json')
for _group in json.loads(r.content)['groups']:
@@ -194,6 +188,4 @@ class Groups(object):
group = Group()
group.import_from_api(_group)
group.joined = True
self.data.append(group)
self.groups.append(group)
+30
View File
@@ -0,0 +1,30 @@
from convore import Convore
convore = Convore('requeststest', 'requeststest')
print convore.account_verify()
print convore.groups[81]
print convore.groups[81]
print '81' in convore.groups
# print convore.groups[81]
# print convore.groups[81]
# print 81 in convore.groups
# print convore.groups[81]
# print convore.groups[81]
# print convore.groups[81].__dict__
# print convore.groups.joined()
# print groups
# print len(groups)
#
# for g in groups:
# print g