-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
95 lines (77 loc) · 2.46 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
88
89
90
91
92
93
94
95
import requests
import json
import webbrowser
from tkinter import *
from tkinter import ttk
import os
data = []
API_KEY = os.environ.get('API_KEY')
root = Tk()
root.title("Upwork Job Screener")
loading_animation = ttk.Progressbar(root, mode='indeterminate')
loading_animation.start()
loading_animation.pack()
skeleton_frame = ttk.Frame(root)
skeleton_frame.pack()
# Set the endpoint URL
endpoint_url = 'https://www.upwork.com/api/jobs/v3/search/jobs'
# Set the parameters for the query
params = {
'q': 'Python',
'sort': 'create_time',
'desc': 'true'
}
# Add the developer key to the headers
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_DEVELOPER_KEY'
}
def get_data():
response = requests.get(endpoint_url, headers=headers, params=params)
if response.status_code == 200:
data = json.loads(response.text)
# display data on the tree
loading_animation.destroy()
show_data()
else:
print(response.status_code)
get_data()
def show_data():
skeleton_frame.destroy()
tree = ttk.Treeview(root)
tree["columns"] = ("title", "client", "budget", "url")
tree.column("#0", width=0, stretch=NO)
tree.column("title", width=150, stretch=NO)
tree.column("client", width=100, stretch=NO)
tree.column("budget", width=100, stretch=NO)
tree.column("url", width=0, stretch=NO)
tree.heading("title", text="Title")
tree.heading("client", text="Client")
tree.heading("budget", text="Budget")
tree.heading("url", text="URL")
tree.pack()
for job in data['jobs']:
tree.insert("", "end", values=(job['title'], job['client']['name'], job['budget'], job['url']))
def open_job(event):
item = tree.identify('item', event.x, event.y)
job_url = tree.item(item, 'values')[3]
webbrowser.open(job_url)
tree.bind("<Double-1>", open_job)
scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)
tree.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=tree.yview)
search_var = StringVar()
search_entry = ttk.Entry(root, textvariable=search_var)
search_entry.pack()
def search():
search_keyword = search_var.get()
# update the params variable with the search keyword
params['q'] = search_keyword
loading_animation.start()
loading_animation.pack()
skeleton_frame.pack()
get_data()
search_button = ttk.Button(root, text="Search", command=search)
search_button.pack()
root.mainloop()