Last active
August 29, 2015 14:08
-
-
Save balzer82/385a1a033fd8168946c7 to your computer and use it in GitHub Desktop.
Checken ob iPhone im Store verfügbar ist und antwittern
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
# -*- coding: utf-8 -*- | |
import requests | |
import tweepy | |
import time | |
import sys | |
# Get Store Number from here: | |
# https://reserve.cdn-apple.com/DE/de_DE/reserve/iPhone/stores.json | |
try: | |
stores = requests.get('https://reserve.cdn-apple.com/DE/de_DE/reserve/iPhone/stores.json').json()['stores'] | |
except: | |
sys.exit(u'Dienst bei Apple derzeit nicht verfügbar. Probier es später noch einmal.') | |
for store in stores: | |
#print store['storeName'] | |
if store['storeName'].startswith('Altmarkt-Galerie'): | |
storenumber = store['storeNumber'] | |
print('Apple Store Dresden hat Store-Nummer \'%s\'' % storenumber) | |
# Nun suchen wir in der Availability nach iPhone 6 64GB: https://reserve.cdn-apple.com/DE/de_DE/reserve/iPhone/availability.json | |
iPhoneCodes = {'MG472ZD/A': 'iPhone 6 16GB grau', | |
'MG482ZD/A': 'iPhone 6 16GB silber', | |
'MG492ZD/A': 'iPhone 6 16GB gold', | |
'MG4A2ZD/A': 'iPhone 6 128GB grau', | |
'MG4C2ZD/A': 'iPhone 6 128GB silber', | |
'MG4E2ZD/A': 'iPhone 6 128GB gold', | |
'MG4F2ZD/A': 'iPhone 6 64GB grau', | |
'MG4H2ZD/A': 'iPhone 6 64GB silber', | |
'MG4J2ZD/A': 'iPhone 6 64GB gold', | |
'MGA82ZD/A': 'iPhone 6Plus 16GB grau', | |
'MGA92ZD/A': 'iPhone 6Plus 16GB silber', | |
'MGAA2ZD/A': 'iPhone 6Plus 16GB gold', | |
'MGAC2ZD/A': 'iPhone 6Plus 128GB grau', | |
'MGAE2ZD/A': 'iPhone 6Plus 128GB silber', | |
'MGAF2ZD/A': 'iPhone 6Plus 128GB gold', | |
'MGAH2ZD/A': 'iPhone 6Plus 64GB grau', | |
'MGAJ2ZD/A': 'iPhone 6Plus 64GB silber', | |
'MGAK2ZD/A': 'iPhone 6Plus 64GB gold'} | |
while True: | |
availability = requests.get('https://reserve.cdn-apple.com/DE/de_DE/reserve/iPhone/availability.json').json() | |
availDD = availability[storenumber] | |
#availDD | |
for iPhoneCode, availability in availDD.iteritems(): | |
if availability: | |
print('Verfügbar: %s' % iPhoneCodes[iPhoneCode]) | |
# Tweet it | |
# Twitter OAuth 2.0 Zeug | |
CONSUMER_KEY = '*************************' | |
CONSUMER_SECRET = '*************************' | |
ACCESS_KEY = '*************************' | |
ACCESS_SECRET = '*************************' | |
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) | |
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET) | |
api = tweepy.API(auth) | |
lookfor = ('6 64GB grau', '6 64GB silber', '6 128GB silber', '6 128GB grau') | |
for iPhoneCode, available in availDD.iteritems(): | |
if available: | |
if iPhoneCodes[iPhoneCode].endswith(lookfor): | |
# This is the message, which should be tweeted | |
message = '@yourusername %s verfügbar' % iPhoneCodes[iPhoneCode] | |
print('%s is verfügbar!!' % iPhoneCodes[iPhoneCode]) | |
print('Geh auf \'https://reserve.cdn-apple.com/DE/de_DE/reserve/iPhone/availability\' und reserviere.') | |
try: | |
print 'Tweet: ' + message | |
api.update_status(message) | |
except Exception, e: | |
print 'Fehler:', e | |
print('Checke in 60s wieder...') | |
time.sleep(60) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment