Skip to content
This repository was archived by the owner on Jun 8, 2024. It is now read-only.

Commit 5665858

Browse files
Merge pull request #41 from ParijatDhar97/master
Added stack overflow parser
2 parents f1bfc2e + 29b0184 commit 5665858

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Stack_Overflow_Parser
2+
3+
Parses SO for your error messages, hope this helps.
4+
5+
Let's connect for some interesting project.
6+

Stack_Overflow_Parser-master/main_.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import shlex
2+
import requests
3+
from subprocess import Popen, PIPE
4+
5+
def execute_and_return(cmd):
6+
"""
7+
Execute the external command and get its exitcode, stdout and stderr.
8+
"""
9+
args = shlex.split(cmd)
10+
proc = Popen(args, stdout=PIPE, stderr=PIPE)
11+
out, err = proc.communicate()
12+
return out, err
13+
14+
def make_request(error):
15+
print("Searching for "+error)
16+
resp = requests.get("https://api.stackexchange.com/"+"2.2/search?order=desc&tagged=python&sort=activity&intitle={}&site=stackoverflow".format(error))
17+
return resp.json()
18+
19+
def get_urls(json_dict):
20+
url_list = []
21+
count = 0
22+
for i in json_dict['items']:
23+
if i["is_answered"]:
24+
url_list.append(i["link"])
25+
count+=1
26+
if count == len(i) or count == 3:
27+
break
28+
import webbrowser
29+
for i in url_list:
30+
webbrowser.open(i)
31+
32+
33+
34+
35+
if __name__ == "__main__":
36+
out, err = execute_and_return("python test.py")
37+
error_message = err.decode("utf-8").strip().split("\r\n")[-1]
38+
print(error_message)
39+
if error_message:
40+
filter_out = error_message.split(":")
41+
print(filter_out)
42+
print(filter_out[0])
43+
json1 = make_request(filter_out[0])
44+
json2 = make_request(filter_out[1])
45+
json = make_request(error_message)
46+
get_urls(json1)
47+
get_urls(json2)
48+
get_urls(json)
49+
else:
50+
print("No errors")
51+

Stack_Overflow_Parser-master/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a = 5 + "b"

0 commit comments

Comments
 (0)