-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
87 lines (71 loc) · 2.65 KB
/
main.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
import PySimpleGUI as sg
from logical import UseGitHubAPI
import webbrowser, os
github_api = UseGitHubAPI()
sg.theme('DarkBlue')
layout = [
[
sg.Text('User Name: '), sg.In(key='input', text_color='Black'),
sg.B('Search', key='search'),
sg.B('view repositories', key='repositories', disabled=True)
],
[
sg.Multiline(key='print_info', size=(90, 30), text_color='Black', disabled=True),
],
[
sg.B('previous', key='previous', disabled=True),
sg.B('go to profile', key='go', disabled=True),
sg.B('next', key='next', disabled=True),
sg.B('git clone', key='clone', disabled=True, pad=(('300', '3'), (None)))
]]
window = sg.Window('GitHub Search', layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
if event == 'search':
user_name = values['input'].replace(' ', '')
github_api.user = user_name
window['print_info'].update(github_api.get_profile_info())
window['go'].update(disabled=False)
window['repositories'].update(disabled=False)
window['previous'].update(disabled=True)
window['next'].update(disabled=True)
window['clone'].update(disabled=True)
if event == 'go':
try:
url = github_api.get_profile_url()
webbrowser.open(url)
except:
...
if event == 'repositories':
repository_now = 0
window['print_info'].update(github_api.get_repository_info(repository_now))
window['previous'].update(disabled=False)
window['next'].update(disabled=False)
window['clone'].update(disabled=False)
if event == 'next':
repository_now += 1
is_repository = github_api.get_repository_info(repository_now)
if isinstance(is_repository, str):
window['print_info'].update(is_repository)
else:
repository_now -=1
if event == 'previous':
repository_now -= 1
if repository_now >= 0:
is_repository = github_api.get_repository_info(repository_now)
if isinstance(is_repository, str):
window['print_info'].update(is_repository)
else:
repository_now +=1
else:
repository_now += 1
if event == 'clone':
clone_url = github_api.get_clone_url(repository_now)
try:
os.system(f'cd ~/ && git clone {clone_url}')
sg.popup('Repository was cloned with success')
except:
sg.popup('Process gave wrong\nCheck if you have git installed on your computer')
window.close()