Skip to content

Commit 3686b5d

Browse files
committed
Addition of separate page for twitter feed
1 parent e9116e5 commit 3686b5d

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

community/urls.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from django.views.generic import TemplateView
99

1010
from gci.views import index as gci_index
11+
from gci.view_twitter import index as twitter_index
1112

1213

1314
def get_index():
@@ -35,4 +36,10 @@ def get_index():
3536
distill_func=get_index,
3637
distill_file='gci/index.html',
3738
),
39+
distill_url(
40+
r'twitter/', twitter_index,
41+
name='twitter',
42+
distill_func=get_index,
43+
distill_file='twitter/index.html',
44+
),
3845
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

gci/view_twitter.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from django.http import HttpResponse
2+
import requests
3+
import json
4+
5+
from .gitorg import get_logo
6+
7+
8+
def index(request):
9+
s = []
10+
11+
org_name = open("org_name.txt", "r").read()
12+
favicon = get_logo(org_name, 16)
13+
with open('_site/favicon.png', 'wb') as favicon_file:
14+
favicon_file.write(favicon)
15+
16+
org_logo = get_logo(org_name)
17+
with open('_site/org_logo.png', 'wb') as org_logo_file:
18+
org_logo_file.write(org_logo)
19+
s.append('<link rel="shortcut icon" type="image/png" '
20+
'href="../static/favicon.png"/>')
21+
s.append('<img src="../static/org_logo.png" alt="'+org_name+'">')
22+
23+
24+
25+
api_data_dump = json.loads(
26+
requests.get('https://gci-leaders.netlify.com/data.json').content)
27+
for item in api_data_dump:
28+
if item['name'] == org_name:
29+
org_twitter_handle = item['twitter_url'].split(
30+
'twitter.com/')[-1]
31+
if org_twitter_handle is not None:
32+
s.append('<a class="twitter-timeline" data-height="1000" '
33+
'data-link-color="#2B7BB9" '
34+
'href="https://twitter.com/{twitter_handle}">'
35+
'Tweets by {twitter_handle}</a> <script async '
36+
'src="https://platform.twitter.com/widgets.js" '
37+
'charset="utf-8"></script>'.format(
38+
twitter_handle=org_twitter_handle))
39+
40+
return HttpResponse('\n'.join(s))

gci/views.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ def gci_overview():
3939
with open('_site/favicon.png', 'wb') as favicon_file:
4040
favicon_file.write(favicon)
4141

42-
org_logo = get_logo(org_name)
43-
with open('_site/org_logo.png', 'wb') as org_logo_file:
44-
org_logo_file.write(org_logo)
45-
4642
s.append('<link rel="shortcut icon" type="image/png" '
4743
'href="static/favicon.png"/>')
4844
s.append('<img src="static/org_logo.png" alt="'+org_name+'">')

templates/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
<ul>
44
<li><a href="/gci/">Google Code-in</a>
55
<li><a href="/activity/">GitHub activity</a>
6+
<li><a href="/twitter/">Twitter Feed</a>
67
</ul>
78
</body>

0 commit comments

Comments
 (0)