Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 390f65d

Browse files
Merge pull request avinashkranjan#1082 from Muskan0/code
Stack Overflow Error Search Auto Tool
2 parents f8c9999 + b526a1b commit 390f65d

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

‎Stackoverflow-Tool/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Package/Script Name
2+
3+
Stack Overflow Error Search Auto Tool
4+
5+
- This script executes your python file.
6+
- And it opens up the related Stack Overflow threads in the browser if there's any error in the script.
7+
8+
## Author(s)
9+
10+
[Muskan Kalra](https://github.com/Muskan0)
11+

‎Stackoverflow-Tool/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
subprocess
2+
requests
3+
webbrowser

‎Stackoverflow-Tool/script.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import subprocess
2+
import requests
3+
import webbrowser
4+
5+
# take the input of the python file
6+
file=input("Enter the python file name(same directory) or enter the proper location\n")
7+
# executing a script and extracting the errors
8+
p = subprocess.run(['python', file], capture_output=True, text=True)
9+
s= p.stderr
10+
s=s.split("\n")
11+
s=s[-2]
12+
errorType= errorMessage= ""
13+
k=len(s)
14+
for i in range(k):
15+
if s[i]==":":
16+
break
17+
errorType=s[:i]
18+
errorMessage=s[i+1:]
19+
20+
# using Stack Exchange API search feature
21+
# parsing the json and extracting the links
22+
URL="https://api.stackexchange.com/2.2/search"
23+
PARAMS= {'intitle': errorType, 'tagged': 'python', 'nottagged':errorMessage, 'sort': 'votes', 'site': 'stackoverflow'}
24+
r= requests.get(url= URL, params= PARAMS)
25+
data= r.json()
26+
27+
links=[]
28+
for i in data['items']:
29+
# get those question links which are answered
30+
if i["is_answered"]==True:
31+
links.append(i["link"])
32+
33+
# opening links the web browser
34+
n1=len(links)
35+
for i in range(7):
36+
if i<n1:
37+
webbrowser.open_new_tab(links[i])

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /