forked from Py-Contributors/awesomeScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_.py
More file actions
57 lines (48 loc) · 1.41 KB
/
main_.py
File metadata and controls
57 lines (48 loc) · 1.41 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import shlex
import requests
from subprocess import Popen, PIPE
def execute_and_return(cmd):
"""
Execute the external command and get its exitcode, stdout and stderr.
"""
args = shlex.split(cmd)
proc = Popen(args, stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
return out, err
def make_request(error):
print("Searching for " + error)
resp = requests.get(
"https://api.stackexchange.com/"
+ "2.2/search?order=desc&tagged=python&sort=activity&intitle={}&site=stackoverflow".format(
error
)
)
return resp.json()
def get_urls(json_dict):
url_list = []
count = 0
for i in json_dict["items"]:
if i["is_answered"]:
url_list.append(i["link"])
count += 1
if count == len(i) or count == 3:
break
import webbrowser
for i in url_list:
webbrowser.open(i)
if __name__ == "__main__":
out, err = execute_and_return("python test.py")
error_message = err.decode("utf-8").strip().split("\r\n")[-1]
print(error_message)
if error_message:
filter_out = error_message.split(":")
print(filter_out)
print(filter_out[0])
json1 = make_request(filter_out[0])
json2 = make_request(filter_out[1])
json = make_request(error_message)
get_urls(json1)
get_urls(json2)
get_urls(json)
else:
print("No errors")