Skip to content

Commit 4ace88a

Browse files
committed
Addition of twitter feed to org overview page
1 parent 5e6defe commit 4ace88a

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

community/urls.py

Lines changed: 2 additions & 1 deletion
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_overview import index as overview_index
1112

1213

1314
def get_index():
@@ -18,7 +19,7 @@ def get_index():
1819

1920
urlpatterns = [
2021
distill_url(
21-
r'^$', TemplateView.as_view(template_name='index.html'),
22+
r'^$', overview_index,
2223
name='index',
2324
distill_func=get_index,
2425
distill_file='index.html',

gci/view_overview.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from django.http import HttpResponse
2+
import requests
3+
import json
4+
5+
from .students import get_students, get_linked_students
6+
from .gitorg import get_logo
7+
from gci.config import get_api_key
8+
9+
10+
def index(request):
11+
try:
12+
client = get_api_key('GCI')
13+
api_key_available = True
14+
except BaseException:
15+
client = None
16+
api_key_available = False
17+
18+
s = []
19+
20+
if api_key_available:
21+
linked_students = list(get_linked_students(get_students()))
22+
org_name = linked_students[0]['organization_name']
23+
favicon = get_logo(org_name, 16)
24+
with open('_site/favicon.png', 'wb') as favicon_file:
25+
favicon_file.write(favicon)
26+
27+
org_logo = get_logo(org_name)
28+
with open('_site/org_logo.png', 'wb') as org_logo_file:
29+
org_logo_file.write(org_logo)
30+
s.append('<link rel="../shortcut icon" type="image/png" '
31+
'href="static/favicon.png"/>')
32+
s.append('<img src="../static/org_logo.png" alt="'+org_name+'">')
33+
else:
34+
s.append(
35+
'WARNING: API key not available. Expect limited functionality')
36+
37+
s.append('<title>Community website</title>')
38+
s.append('<ul><li><a href="/gci/">Google Code-in</a>'
39+
'<li><a href="/activity/">GitHub activity</a></ul>')
40+
41+
if api_key_available:
42+
api_data_dump = json.loads(
43+
requests.get('https://gci-leaders.netlify.com/data.json').content)
44+
for item in api_data_dump:
45+
if item['name'] == org_name:
46+
org_twitter_handle = item['twitter_url'].split(
47+
'twitter.com/')[-1]
48+
if org_twitter_handle is not None:
49+
s.append('<a class="twitter-timeline" data-height="1000" '
50+
'data-link-color="#2B7BB9" '
51+
'href="https://twitter.com/{twitter_handle}">'
52+
'Tweets by {twitter_handle}</a> <script async '
53+
'src="https://platform.twitter.com/widgets.js" '
54+
'charset="utf-8"></script>'.format(
55+
twitter_handle=org_twitter_handle))
56+
57+
return HttpResponse('\n'.join(s))

gci/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def gci_overview():
4444
org_logo_file.write(org_logo)
4545

4646
s.append('<link rel="shortcut icon" type="image/png" '
47-
'href="../static/favicon.png"/>')
48-
s.append('<img src="../static/org_logo.png" alt="'+org_name+'">')
47+
'href="static/favicon.png"/>')
48+
s.append('<img src="static/org_logo.png" alt="'+org_name+'">')
4949
s.append('<h2>Welcome</h2>')
5050
s.append('Hello, world. You are at the {org_name} community GCI website.'
5151
.format(org_name=org_name))

0 commit comments

Comments
 (0)