Created
November 12, 2020 07:42
-
-
Save arashrasoulzadeh/51bc0452c29e81674cc564e2d5eab339 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
cookies = {'PHPSESSID': 'YOUR_SESS_ID_FROM_WEBSITE'} | |
def sort_by_values_len(dict): | |
dict_len = {key: len(value) for key, value in dict.items()} | |
import operator | |
sorted_key_list = sorted( | |
dict_len.items(), key=operator.itemgetter(1), reverse=True) | |
sorted_dict = [{item[0]: dict[item[0]]} for item in sorted_key_list] | |
return sorted_dict | |
req = requests.post( | |
'https://snappfood.ir/profile/ajax/orders', cookies=cookies) | |
resp = req.json() | |
dictionary = {} | |
for order in resp['data']: | |
if order['vendorId'] in dictionary: | |
dictionary[order['vendorId']].append(order) | |
else: | |
dictionary[order['vendorId']] = [order] | |
sorted_by_count = sort_by_values_len(dictionary) | |
top10 = list(sorted_by_count)[:10] | |
for item in top10: | |
first_key = next(iter(item)) | |
data = item[first_key] | |
print("{} orders from {}".format(len(data), data[0]['englishTitle'])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment