Skip to content

Commit 60225f5

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

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

community/urls.py

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

1010
from gci.views import index as gci_index
11-
11+
from gci.view_overview import index as overview_index
1212

1313
def get_index():
1414
# The index URI regex, ^$, contains no parameters, named or otherwise.
@@ -18,7 +18,7 @@ def get_index():
1818

1919
urlpatterns = [
2020
distill_url(
21-
r'^$', TemplateView.as_view(template_name='index.html'),
21+
r'^$', overview_index,
2222
name='index',
2323
distill_func=get_index,
2424
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))

0 commit comments

Comments
 (0)