-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.py
104 lines (85 loc) · 3.18 KB
/
data.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
import os.path
import os.path
import requests
import rumps
from bs4 import BeautifulSoup
import url
from gitContent import GitContentMeue
from url import *
class GetUserName(rumps.Window):
"""A dialog which contain a text input for getting username"""
def __init__(self):
super().__init__("Your GitHub user name ", "Config")
self.icon = "gitIco.png"
class GetData():
"""Get data from Git"""
def __init__(self):
# chech if there is data file or not
if not self.isThereFile():
# get username via rumps window
self.saveUserName(self.getUserName())
self.username = self.readDate()
def isThereFile(self):
"""chech if the userName saved or not"""
return os.path.exists("data.txt")
def readDate(self):
"""Get username from .txt file."""
with open("data.txt") as file:
return file.read()
def saveUserName(self, username):
"""save username to .txt file"""
with open("data.txt", "w") as file:
file.write(username)
def getFollowers(self):
"""Get followers count from Git"""
response = requests.get("https://github.com/" + self.username)
soup = BeautifulSoup(response.text, "html.parser")
soup = soup.findAll("span", "text-bold color-fg-default")[0]
return soup.text
def getFollowing(self):
"""Get following count from Git"""
response = requests.get("https://github.com/" + self.username)
soup = BeautifulSoup(response.text, "html.parser")
soup = soup.findAll("span", "text-bold color-fg-default")[1]
return soup.text
def getUserName(self):
"""Get username from user"""
getUser = GetUserName()
res = getUser.run()
return res.text
def getRep(self):
"""Get user repositorys name"""
try:
response = requests.get(url=URL + self.username + Rep)
response.raise_for_status()
except:
rumps.alert("Network Error", "Check your network connection", ok=None, icon_path="gitIco.png")
return ["error"]
soup = BeautifulSoup(response.text, "html.parser")
soup = soup.findAll("a", attrs={"itemprop": "name codeRepository"})
return soup
def getRepoContent(self, name):
"""Get repository Contents"""
try:
response = requests.get(url=url.URL + self.username + "/" + name)
soup = BeautifulSoup(response.text, "html.parser")
soup = soup.findAll("div", role="row", class_="Box-row--focus-gray")
except:
return "error"
finally:
list = []
for i in soup:
a = i.find_next("a", class_="js-navigation-open Link--primary")
list.append(GitContentMeue(a['title'],
i.find_next("svg")["aria-label"], "", a["href"]))
return list
# getData = GetData()
# t1 = Thread(target=getData.getRepoContent , args=["name"])
# t1.start()
# def monitor(thread):
# while thread.is_alive():
# time.sleep(0.1)
# print("loading.")
# print()
# t2 = Thread(target=monitor , args=[t1])
# t2.start()