Commit 711b3060 authored by Samarth Joshi's avatar Samarth Joshi

Adding q4

parent 7c1f4fd9
#!/usr/bin/env python3
\ No newline at end of file
#!/usr/bin/env python3
from stackapi import StackAPI
import csv
SITE = StackAPI('stackoverflow', key="M4CoY9wjxmjb9IjujPG*aQ((", access_token="EhiByzpIjSeAL1f4rs1abw))")
csvheader = [ "question_id", "tag", "link", "tags", "accepted_answer" ]
while True:
input_tags = input()
input_tags = input_tags.lower()
filename = "_".join(input_tags.split(' '))
filename_with_extn = filename + '.csv'
result = SITE.fetch('search/advanced', page=1 ,pagesize=50, order="desc", sort="votes", q=input_tags, accepted=True)
with open(filename_with_extn, 'w', newline='') as csvfile:
csvwriter = csv.writer(csvfile, delimiter=',', quoting=csv.QUOTE_MINIMAL)
csvwriter.writerow(csvheader)
for item in result['items']:
row = []
row.append(item['question_id'])
row.append(filename)
row.append(item['link'])
row.append(item['tags'])
row.append(f"{item['link']}/#{item['accepted_answer_id']}")
csvwriter.writerow(row)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment