|
2 | 2 | import requests
|
3 | 3 | import json
|
4 | 4 |
|
5 |
| -from .students import get_students, get_linked_students |
6 | 5 | from .gitorg import get_logo
|
7 |
| -from gci.config import get_api_key |
8 | 6 |
|
9 | 7 |
|
10 | 8 | 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 | 9 | s = []
|
19 | 10 |
|
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)) |
| 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)) |
56 | 39 |
|
57 | 40 | return HttpResponse('\n'.join(s))
|
0 commit comments