-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
0 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1 @@ | ||
from django.contrib import admin | ||
|
||
from amelie.twitter.models import TwitterAccount, Tweet | ||
|
||
|
||
class TwitterAccountAdmin(admin.ModelAdmin): | ||
list_display = ('screenname', 'oauth_token', 'is_active', 'date_added',) | ||
search_fields = ('screenname',) | ||
list_filter = ('date_added', 'is_active',) | ||
date_hierarchy = 'date_added' | ||
|
||
|
||
class TweetAdmin(admin.ModelAdmin): | ||
list_display = ('id', 'timestamp', 'account', 'content') | ||
search_fields = ('account__screenname', 'content', ) | ||
list_filter = ('account',) | ||
date_hierarchy = 'timestamp' | ||
|
||
|
||
admin.site.register(TwitterAccount, TwitterAccountAdmin) | ||
admin.site.register(Tweet, TweetAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1 @@ | ||
from django.db import models | ||
|
||
|
||
class TwitterAccountManager(models.Manager): | ||
def get_queryset(self): | ||
return super(TwitterAccountManager, self).get_queryset().filter(is_active=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,7 @@ | ||
from datetime import datetime, timedelta | ||
|
||
from django.utils import timezone | ||
|
||
from amelie.twitter.models import TwitterAccount, Tweet | ||
|
||
update_interval = timedelta(seconds=300) | ||
|
||
|
||
def update_streams(): | ||
twitter_accounts = TwitterAccount.objects.filter(is_active=True, last_update__lt=(timezone.now() - update_interval)) | ||
|
||
for account in twitter_accounts: | ||
twython_instance = account.get_twython_instance() | ||
tweet_set = None | ||
if account.last_tweet is "": | ||
tweet_set = twython_instance.get_user_timeline(screen_name=account.screenname, count=20) | ||
else: | ||
tweet_set = twython_instance.get_user_timeline(screen_name=account.screenname, since_id=account.last_tweet) | ||
|
||
if(len(tweet_set) > 0): | ||
account.last_tweet = tweet_set[0]["id"] | ||
account.image_url = tweet_set[0]["user"]["profile_image_url_https"] | ||
#twitter uses _normal images as default, we want the big images | ||
#sadly twitter doesn't provide them in their api format, so we just replace normal with bigger | ||
account.image_url.replace("normal", "bigger") | ||
account.last_update = timezone.now() | ||
account.save() | ||
|
||
utc = timezone.utc | ||
for raw_tweet in tweet_set: | ||
date = datetime.strptime(raw_tweet["created_at"], "%a %b %d %H:%M:%S +0000 %Y") | ||
date = date.replace(tzinfo=utc) | ||
tweet = Tweet(account=account, content=raw_tweet["text"], timestamp=date) | ||
tweet.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,4 @@ | |
|
||
urlpatterns = [ | ||
path('', views.index, name='index'), | ||
path('new/', views.new_tweet, name='new_tweet'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters