Created
September 13, 2019 05:36
-
-
Save kyletaylored/405101655490f07a2b40b1d4f411ab21 to your computer and use it in GitHub Desktop.
Get actual mobile app information from Adwords platform domain IDs.
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 csv | |
import requests | |
import json | |
import time | |
from pprint import pprint | |
itunes = "https://api.appmonsta.com/v1/stores/itunes/details/" | |
android = "https://api.appmonsta.com/v1/stores/android/details/" | |
api_key = "API_KEY" | |
def platform(id): | |
char = id[:1] | |
if char.isdigit(): | |
return 'ios' | |
return 'android' | |
def platform_url(id): | |
char = id[:1] | |
if char.isdigit(): | |
return itunes + id + ".json?country=US" | |
return android + id + ".json?country=US" | |
with open('dest.csv', 'w') as destcsv: | |
filewriter = csv.writer(destcsv) | |
with open('source.csv', 'r') as sourcecsv: | |
reader = csv.reader(sourcecsv) | |
# read file row by row | |
for row in reader: | |
domain = row[0].split("::") | |
if len(domain) > 1: | |
domainid = domain[1].split("-") | |
if len(domainid) == 2: | |
appid = domainid[1] | |
data = [] | |
url = platform_url(appid) | |
print(url) | |
res = requests.get(url, auth=(api_key, 'pass')) | |
app = json.loads(res.text) | |
if 'app_name' in app: | |
data.append(row[0]) | |
data.append(appid) | |
data.append(platform(appid)) | |
data.append(app['app_name']) | |
data.append(app['all_rating']) | |
data.append(app['all_rating_count']) | |
data.append(app['genre']) | |
data.append(str.join(' / ', app['genres'])) | |
data.append(app['price_value']) | |
filewriter.writerow(data) | |
time.sleep(.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment