# version 1.0.0 import re import urllib.request import pprint import datetime import time import ast import pprint import os from collections import OrderedDict import msvcrt user_setting_default_refresh_time = 15 # this is the number of seconds the script will wait between scans urlGeneric = "http://chat-us.riftgame.com:8080/chatservice/zoneevent/list?shardId=" urlTime = "http://chat-us.riftgame.com:8080/chatservice/time" shardList = {"Seastone":"1701", "Greybriar":"1702", "Deepwood":"1704", "Wolfsbane":"1706", "Faeblight":"1707", "Laethys":"1708", "Hailol":"1721"} resultsArray = {"none":"none"} while 1: resultsArray.clear() resultsCount=0 timestamp = int(time.time()) rescan_target = timestamp + user_setting_default_refresh_time mylocaltime = datetime.datetime.fromtimestamp(timestamp) for shard in shardList: try: reqZE = urllib.request.Request(urlGeneric+shardList[shard]) responseZE = urllib.request.urlopen(reqZE) s = responseZE.read() s2=s.decode("utf-8") reqTime = urllib.request.Request(urlTime) responseTime = urllib.request.urlopen(reqTime) s3 = responseTime.read() s4=s3.decode("utf-8") except: # this is just for debug purposes, or if the server connection fails s2="""{"status":"success","data":[{"zone":"Fake Shimmersand","zoneId":6},{"zone":"Fake Ember Isle","zoneId":1992854106,"name":"Unstable Ember Isle","started":1392580211},{"zone":"Fake Silverwood","zoneId":12},{"zone":"Fake Stillmoor","zoneId":26},{"zone":"Fake Moonshade Highlands","zoneId":24},{"zone":"Fake Iron Pine Peak","zoneId":22},{"zone":"Fake Freemarch","zoneId":19},{"zone":"Fake Stonefield","zoneId":1481781477,"name":"Visions of Future Past","started":1392576584},{"zone":"Fake Scarwood Reach","zoneId":20},{"zone":"Fake Droughtlands","zoneId":336995470},{"zone":"Fake Gloamwood","zoneId":27},{"zone":"Fake Scarlet Gorge","zoneId":26580443},{"zone":"Fake Kingdom of Pelladane","zoneId":479431687},{"zone":"Fake Cape Jule","zoneId":1770829751},{"zone":"Fake Ashora","zoneId":790513416},{"zone":"Fake Seratos","zoneId":1494372221},{"zone":"Fake Steppes of Infinity","zoneId":798793247},{"zone":"Fake Eastern Holdings","zoneId":1213399942,"name":"On the Hunt","started":1392580420},{"zone":"Fake City Core","zoneId":1967477725},{"zone":"Fake Morban","zoneId":956914599},{"zone":"Fake Ardent Domain","zoneId":1446819710},{"zone":"Fake Kingsward","zoneId":1300766935,"name":"Unstable Kingsward","started":1392535321},{"zone":"The Fake Dendrome","zoneId":282584906}]}""" s4=999 evals2=ast.literal_eval(s2) # convert the webserver's response to a dict zEvents=evals2['data'] # save off the current dataset, for readability only for i in range(0,len(zEvents)): if 'started' in zEvents[i]: thisEvent=zEvents[i] shardAndZone = " " + shard + ", " + thisEvent['zone'] + ": " if "Unstable" in thisEvent['name']: remaining = 60*30-(float(s4)-thisEvent['started']) filler_char=" " time_string=" ("+str(datetime.timedelta(seconds=remaining))+" remaining)" else: elapsed = float(s4)-thisEvent['started'] filler_char=" " time_string=" ("+str(datetime.timedelta(seconds=elapsed))+" elapsed)" resultsArray[resultsCount]=shardAndZone.ljust(40,filler_char)+" "+thisEvent['name']+time_string resultsCount=resultsCount+1 # clear then print new info os.system('CLS') print(mylocaltime.strftime('%Y-%m-%d %H:%M:%S') + "\n") for i in range(0,len(resultsArray)): # loop thru all results if 'Goboro Reef' in resultsArray[i]: # find bloodfire print(resultsArray[i]) # print for i in range(0,len(resultsArray)): # loop thru all results if 'Draumheim' in resultsArray[i]: # find Power of Nightmares print(resultsArray[i]) # print for i in range(0,len(resultsArray)): # loop thru all results if 'Tarken Glacier' in resultsArray[i]: # find Power of Nightmares print(resultsArray[i]) # print for i in range(0,len(resultsArray)): # loop thru all results if 'Tyrant' in resultsArray[i]: # find Power of Nightmares print(resultsArray[i]) # print print("\n") # after it loops thru all the shards and prints, wait until current time reaches rescan_target, OR a keystroke is received while int(time.time()) < rescan_target: if msvcrt.kbhit(): rescan_target = 0 # set to start of epoch while msvcrt.kbhit(): # as long as there is still a keystroke waiting... msvcrt.getch() # remove one character from the queue else: time.sleep(1) # allZones = {'zone':'ID'} # for i in range(0,len(zEvents)): # thisEvent=zEvents[i] # if 'zone' in thisEvent and 'zoneId' in thisEvent: # allZones[thisEvent['zone'].ljust(21," ")]=str(thisEvent['zoneId']).zfill(12) # zero fill to 12 places to help sorting # pprint.pprint(OrderedDict(sorted(allZones.items(), key=lambda x: x[0])))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question