Last active
June 12, 2025 11:29
-
-
Save devandanger/cccc2357c64292839ce81219271ac2c8 to your computer and use it in GitHub Desktop.
app_review_extract
This file contains hidden or 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 jwt | |
| import time | |
| from datetime import datetime, timedelta | |
| import csv | |
| # --- CONFIGURATION --- | |
| ISSUER_ID = '' | |
| KEY_ID = '' | |
| APP_ID = '' | |
| PRIVATE_KEY_PATH = '' # Path to your API key file | |
| # --- JWT GENERATION --- | |
| def generate_token(): | |
| with open(PRIVATE_KEY_PATH, 'r') as f: | |
| private_key = f.read() | |
| now = int(time.time()) | |
| payload = { | |
| 'iss': ISSUER_ID, | |
| 'exp': now + 20 * 60, | |
| 'aud': 'appstoreconnect-v1' | |
| } | |
| headers = { | |
| 'alg': 'ES256', | |
| 'kid': KEY_ID, | |
| 'typ': 'JWT' | |
| } | |
| token = jwt.encode(payload, private_key, algorithm='ES256', headers=headers) | |
| return token | |
| # --- FETCH REVIEWS --- | |
| def fetch_reviews(): | |
| token = generate_token() | |
| url = f'https://api.appstoreconnect.apple.com/v1/apps/{APP_ID}/customerReviews' | |
| headers = { | |
| 'Authorization': f'Bearer {token}' | |
| } | |
| response = requests.get(url, headers=headers) | |
| if response.status_code == 200: | |
| data = response.json() | |
| reviews = [] | |
| for review in data.get('data', []): | |
| attributes = review.get('attributes', {}) | |
| rating = attributes.get('rating') | |
| title = attributes.get('title') | |
| body = attributes.get('body') | |
| reviewer = attributes.get('reviewerNickname') | |
| created_date = attributes.get('createdDate') | |
| territory = attributes.get('territory') | |
| if body is not None and rating is not None: | |
| reviews.append({ | |
| 'rating': rating, | |
| 'title': title, | |
| 'body': body, | |
| 'reviewerNickname': reviewer, | |
| 'createdDate': created_date, | |
| 'territory': territory | |
| }) | |
| else: | |
| print(f"[DEBUG] Unexpected review attributes: {attributes}") | |
| # Write to CSV | |
| with open('apple_reviews.csv', 'w', newline='', encoding='utf-8') as csvfile: | |
| fieldnames = ['rating', 'title', 'body', 'reviewerNickname', 'createdDate', 'territory'] | |
| writer = csv.DictWriter(csvfile, fieldnames=fieldnames) | |
| writer.writeheader() | |
| for row in reviews: | |
| writer.writerow(row) | |
| print(f"Saved {len(reviews)} reviews to apple_reviews.csv") | |
| else: | |
| print('Failed to fetch reviews:', response.status_code, response.text) | |
| if __name__ == '__main__': | |
| fetch_reviews() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment