forked from aman-roy/StalkHub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
111 lines (90 loc) · 2.98 KB
/
helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# This file has all the functions which will
# be used in retriving data from GitHub API.
import urllib2
import json
import os
try:
# Getting client id and secret for extending rate limit
secret = '?client_id=' + os.environ.get('CLID') + '&client_secret=' + os.environ.get('CLSEC')
except:
secret = ''
# Basic retrival of data from
# https://api.github.com/users/user_name
def basic_retrive(user_name):
# concatenate user name to create link
link = "https://api.github.com/users/" + user_name + secret
# empty list for collecting things I need
box = []
# Try to open link and if failed return None
try:
response = urllib2.urlopen(link)
data = json.load(response)
if not data:
return None
except:
return None
# Check if the link opened is user type
if not data['type'] == "User":
return None
box = dict()
# Collect everything in box and return box
try:
box['login'] = data['login']
box['avatar_url'] = data['avatar_url']
box['html_url'] = data['html_url']
box['name'] = data['name']
box['company'] = data['company']
if (("http" not in data['blog']) and (data['blog'] !="")):
data['blog'] = str("http://" + data['blog'])
box['blog'] = data['blog']
box['location'] = data['location']
box['bio'] = data['bio']
box['public_repos'] = data['public_repos']
box['public_gists'] = data['public_gists']
box['followers'] = data['followers']
box['following'] = data['following']
#print box
return box
except:
return None
def watch_list(user_name):
# concatenate user name to create link
link = "https://api.github.com/users/" + user_name + "/subscriptions" + secret
# empty list for collecting things I need
box = []
# Try to open link and if failed return None
try:
response = urllib2.urlopen(link)
data = json.load(response)
if not data:
return None
except:
return None
# pack the box with info we need
for i in range(len(data)):
box_feed = {}
box_feed["name"] = data[i]["name"]
box_feed["html_url"] = data[i]["html_url"]
box.append(box_feed)
return box
def organizations(user_name):
# concatenate user name to create link
link = "https://api.github.com/users/" + user_name + "/orgs" + secret
# empty list for collecting things I need
box = []
# Try to open link and if failed return None
try:
response = urllib2.urlopen(link)
data = json.load(response)
if not data:
return None
except:
return None
# pack the box with info we need
for i in range(len(data)):
box_feed = {}
box_feed["name"] = data[i]["login"]
box_feed["url"] = "https://github.com/" + data[i]["login"]
box_feed["icon"] = data[i]["avatar_url"]
box.append(box_feed)
return box