-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathverify_github_usernames.py
More file actions
42 lines (34 loc) · 1 KB
/
verify_github_usernames.py
File metadata and controls
42 lines (34 loc) · 1 KB
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
import github
import os
# import requests
# import shutil
# import yaml
from dotenv import load_dotenv
from os.path import join, dirname
try:
dotenv_path = join(dirname(__file__), '.env')
load_dotenv(dotenv_path)
except Exception as e:
print "\nMissing .env file\n"
GITHUB_ACCESS_TOKEN = os.environ.get('GITHUB_ACCESS_TOKEN', None)
STUDENTS_FILE = 'github-student-usernames.txt'
OUTPUT_FILE = 'bad-github-usernames.txt'
def is_valid_user(g, username):
try:
g.get_user(username)
return True
except:
return False
def verify_github_users():
g = github.Github(GITHUB_ACCESS_TOKEN)
out = open(OUTPUT_FILE, 'w')
with open(STUDENTS_FILE) as rd:
student_usernames = [username.strip() for username in rd.readlines()]
for student in student_usernames:
if student:
if not is_valid_user(g, student):
print student
out.write(student + '\n')
out.close()
if __name__ == '__main__':
verify_github_users()