From e8f9e99853963b25b92b8b4cd25c96828cac063d Mon Sep 17 00:00:00 2001 From: dob9601 Date: Tue, 12 Dec 2017 17:56:36 +0000 Subject: [PATCH] Addition of separate page for twitter feed --- community/urls.py | 7 +++++++ gci/view_twitter.py | 30 ++++++++++++++++++++++++++++++ gci/views.py | 5 ----- templates/index.html | 1 + 4 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 gci/view_twitter.py diff --git a/community/urls.py b/community/urls.py index 6e65f3c5..8eb680b9 100644 --- a/community/urls.py +++ b/community/urls.py @@ -8,6 +8,7 @@ from django.views.generic import TemplateView from gci.views import index as gci_index +from gci.view_twitter import index as twitter_index def get_index(): @@ -35,4 +36,10 @@ def get_index(): distill_func=get_index, distill_file='gci/index.html', ), + distill_url( + r'twitter/', twitter_index, + name='twitter', + distill_func=get_index, + distill_file='twitter/index.html', + ), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/gci/view_twitter.py b/gci/view_twitter.py new file mode 100644 index 00000000..7ac7bf33 --- /dev/null +++ b/gci/view_twitter.py @@ -0,0 +1,30 @@ +from django.http import HttpResponse +import requests +import json + +from .gitorg import get_logo + + +def index(request): + s = [] + + org_name = open('org_name.txt', 'r').read() + s.append('') + + api_data_dump = json.loads( + requests.get('https://gci-leaders.netlify.com/data.json').content) + for item in api_data_dump: + if item['name'] == org_name: + org_twitter_handle = item['twitter_url'].split( + 'twitter.com/')[-1] + if org_twitter_handle is not None: + s.append('' + 'Tweets by {twitter_handle} '.format( + twitter_handle=org_twitter_handle)) + + return HttpResponse('\n'.join(s)) diff --git a/gci/views.py b/gci/views.py index 0f0c77fb..8c3f6e78 100644 --- a/gci/views.py +++ b/gci/views.py @@ -39,13 +39,8 @@ def gci_overview(): with open('_site/favicon.png', 'wb') as favicon_file: favicon_file.write(favicon) - org_logo = get_logo(org_name) - with open('_site/org_logo.png', 'wb') as org_logo_file: - org_logo_file.write(org_logo) - s.append('') - s.append(''+org_name+'') s.append('

Welcome

') s.append('Hello, world. You are at the {org_name} community GCI website.' .format(org_name=org_name)) diff --git a/templates/index.html b/templates/index.html index 4f2c5ca0..6f706852 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,5 +3,6 @@