-
Notifications
You must be signed in to change notification settings - Fork 0
/
automate.py
48 lines (35 loc) · 1.19 KB
/
automate.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
import json
import subprocess
import re
import os
BASE_URL = "https://github.com/scalable-web-systems/"
f = open('config.json')
data = json.load(f)
exceptions = ['README.md']
# Helper Function to get file names in a directory
def get_file_names(dir):
files = os.listdir(dir)
file_names = []
for file in files:
if '.md' in file and file not in exceptions:
file_names.append(file)
return file_names
def get_matching_dir(num):
folders = os.listdir("docs")
for folder in folders:
if str(num) in folder:
return folder
for repo_name in data['repos']:
print(repo_name)
subprocess.run(["git", "clone", BASE_URL+repo_name])
file_names = get_file_names(repo_name)
for file_name in file_names:
print(file_name)
file_dir = repo_name + "/" + file_name
with open(file_dir, 'r') as f:
text = f.read()
first_line = text.split('\n')[0]
to_folder_name = get_matching_dir(int(re.search(r'\d+', first_line).group()))
move_to = "docs" + "/" + to_folder_name
subprocess.run(['mv', file_dir, move_to])
subprocess.run(["rm", "-rf", repo_name])