Created
July 3, 2012 04:26
-
-
Save keunhong/3037716 to your computer and use it in GitHub Desktop.
Nag Verizon for order status
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
#!/usr/bin/python | |
import urllib.parse | |
import urllib.request | |
import re | |
import threading | |
import json | |
import pprint | |
from datetime import datetime | |
ORDER_NUMBER = "" | |
LAST_NAME = "" | |
UPDATE_INTERVAL = 5.0 | |
SUBMIT_URL = "https://preorder.verizonwireless.com/iconic/iconic/screens/IconicSearch.do" | |
ORDER_DICT = { | |
'C': "We received your order and it is in process.", | |
'S': "Your order has been sent for processing.", | |
'E': "There is an error in your order. Please refer to the email sent for more information.", | |
'X': "Your Order has been Cancelled.", | |
'B': "We received your order and it is in process. Payment not taken yet.", | |
'T': "We received your cart", | |
} | |
def fetch_page(): | |
values = { | |
'confNum': ORDER_NUMBER, | |
'lastName': LAST_NAME, | |
} | |
data = urllib.parse.urlencode(values).encode('utf-8') | |
req = urllib.request.Request(SUBMIT_URL, data) | |
req.add_header('Referer', "https://preorder.verizonwireless.com/iconic/iconic/screens/IconicSearchInit.do") | |
request = urllib.request.urlopen(req) | |
return request.read().decode('utf-8') | |
def get_and_print(): | |
page_contents = fetch_page() | |
parsed = json.loads(page_contents) | |
status_code = parsed['iconicStatus'] | |
status_detailed = ORDER_DICT[status_code] | |
current_time = str(datetime.now()) | |
if parsed['itemDetailsList']: | |
status_detailed += " Tracking #: %s" % parsed['itemDetailsList'][0]['shipmentTrackingNumber'] | |
print("[%s] %s" % (current_time, status_detailed)) | |
threading.Timer(UPDATE_INTERVAL, get_and_print).start() | |
def main(): | |
get_and_print(); | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment