mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +00:00
Added recent_posts function to pull recent posts/comments from API
This commit is contained in:
@@ -36,6 +36,19 @@ class RedditAccount(models.Model):
|
||||
self.date_created = datetime.fromtimestamp(data['created_utc'])
|
||||
self.last_update = datetime.now()
|
||||
|
||||
def recent_posts(self):
|
||||
try:
|
||||
jsondoc = json.load(urllib.urlopen("http://reddit.com/user/%s.json" % self.username))
|
||||
except:
|
||||
raise self.DoesNotExist
|
||||
|
||||
posts = []
|
||||
for item in jsondoc['data']['children']:
|
||||
posts.append(item['data'])
|
||||
|
||||
return posts
|
||||
|
||||
|
||||
class Meta:
|
||||
app_label = 'reddit'
|
||||
ordering = ['username']
|
||||
|
||||
Reference in New Issue
Block a user