This repository has been archived by the owner on Nov 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathshopinfo.py
58 lines (53 loc) · 2.07 KB
/
shopinfo.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
import json
import requests
import csv
from datetime import datetime
import pandas as pd
print('''
___________________ __
/ ____/_ __/ ___/\ \/ /
/ __/ / / \__ \ \ /
/ /___ / / ___/ / / /
/_____/ /_/ /____/ /_/
By Mangetsuuuuuuu
''')
store = input("Enter Store Name : ")
api_key = input("Enter Your Api : ")
uu = slice(0,-13)
print("Always Drink Water !! ")
try:
r = requests.get(f'https://openapi.etsy.com/v2/shops/{store}?includes=Listings:active&api_key={api_key}').text
except:
print("Somthing Wrong !! check Api or StoreName")
exit()
slm = ['title','price','quantity','views','fav','creation','url','tags']
with open(f'{store}.csv' , 'a', encoding='utf8') as done:
writer = csv.writer(done)
writer.writerow(slm)
data = json.loads(r)
Shop_Name=data['results'][0]['shop_name']
Shop_creation=str(pd.to_datetime(datetime.today()).date() - pd.to_datetime(datetime.fromtimestamp(data['results'][0]['creation_tsz'])).date())
days=Shop_creation[uu]
ok =[f'Shop Name {Shop_Name}',f'Shop creation {days}']
with open(f'{store}.csv' , 'a', encoding='utf8') as done:
writer = csv.writer(done)
writer.writerow(ok)
page=[1,2,3,4,5]
for i in page:
r = requests.get(f'https://openapi.etsy.com/v2/shops/{store}/listings/active?&limit=100&page={i}&api_key={api_key}').text
data = json.loads(r)
for i in data['results']:
title=i.get('title')
price=i.get('price')
quantity=str(+i.get('quantity'))
views=str(i.get('views'))
fav = str(i.get('num_favorers'))
date = str(pd.to_datetime(datetime.today()).date() - pd.to_datetime(datetime.fromtimestamp(i.get('original_creation_tsz'))).date())
days=date[uu]
url =i.get('url')
tags =','.join(i['tags'])
cool = [title,price,quantity,views,fav,days,url,tags]
with open(f'{store}.csv' , 'a', encoding='utf8') as done:
writer = csv.writer(done)
writer.writerow(cool)
print("Done!!")