Skip to content

Commit

Permalink
Addition of separate page for twitter feed
Browse files Browse the repository at this point in the history
  • Loading branch information
dob9601 committed Dec 13, 2017
1 parent e9116e5 commit e8f9e99
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
7 changes: 7 additions & 0 deletions community/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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)
30 changes: 30 additions & 0 deletions gci/view_twitter.py
Original file line number Diff line number Diff line change
@@ -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('<link rel="shortcut icon" type="image/png" '
'href="../static/favicon.png"/>')

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('<a class="twitter-timeline" data-height="1000" '
'data-link-color="#2B7BB9" '
'href="https://twitter.com/{twitter_handle}">'
'Tweets by {twitter_handle}</a> <script async '
'src="https://platform.twitter.com/widgets.js" '
'charset="utf-8"></script>'.format(
twitter_handle=org_twitter_handle))

return HttpResponse('\n'.join(s))
5 changes: 0 additions & 5 deletions gci/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('<link rel="shortcut icon" type="image/png" '
'href="static/favicon.png"/>')
s.append('<img src="static/org_logo.png" alt="'+org_name+'">')
s.append('<h2>Welcome</h2>')
s.append('Hello, world. You are at the {org_name} community GCI website.'
.format(org_name=org_name))
Expand Down
1 change: 1 addition & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<ul>
<li><a href="/gci/">Google Code-in</a>
<li><a href="/activity/">GitHub activity</a>
<li><a href="/twitter/">Twitter Feed</a>
</ul>
</body>

0 comments on commit e8f9e99

Please sign in to comment.