Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@LyndonArmitage
Created May 23, 2013 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save LyndonArmitage/5638200 to your computer and use it in GitHub Desktop.
Save LyndonArmitage/5638200 to your computer and use it in GitHub Desktop.
A Planetside 2 Python bot that periodically told me what the last event was that happened on the server I play on via a text to speech engine called pyttsx and prints it to the console.
import requests
import pyttsx
import time
__author__ = 'Lyndon'
# SOE documentation: https://census.soe.com/
# Faction IDs
def get_faction(id):
return {
"1": "Vanu Sovereignty",
"2": "New Conglomerate",
"3": "Terran Republic"
}[id]
# Zone IDs
def get_zone(id):
return {
"2": "Indar",
"6": "Amerish",
"8": "Esamir"
}[id]
def get_facility_name(zone_id, facility_id):
if get_zone(zone_id) == "Indar":
r = requests.get("http://census.soe.com/get/ps2-beta/indarmap/?id=" + facility_id + "&c:show=facility")
facility_obj = r.json()
return facility_obj["indarmap_list"][0]["facility"]["en"]
elif get_zone(zone_id) == "Amerish":
r = requests.get("http://census.soe.com/get/ps2-beta/amerishmap/?id=" + facility_id + "&c:show=facility")
facility_obj = r.json()
return facility_obj["amerishmap_list"][0]["facility"]["en"]
elif get_zone(zone_id) == "Esamir":
r = requests.get("http://census.soe.com/get/ps2-beta/esamirmap/?id=" + facility_id + "&c:show=facility")
facility_obj = r.json()
return facility_obj["esamirmap_list"][0]["facility"]["en"]
# Get server names
def __get_server_dictionary():
r = requests.get("https://census.soe.com/s:LyndonArmitage/get/ps2-beta/world/")
server_obj = r.json()
dic = {}
for world in server_obj["world_list"]:
dic[world["server_id"]] = world["name"]["en"]
return dic
server_names = __get_server_dictionary()
engine = pyttsx.init()
def lastEventOnServer(world_id="13"):
r = requests.get("https://census.soe.com/s:LyndonArmitage/get/ps2-beta/world_event/" + world_id)
event_obj = r.json()
if event_obj["world_event_list"][0]["faction_new"] == event_obj["world_event_list"][0]["faction_old"]:
faction_name = get_faction(event_obj["world_event_list"][0]["faction_new"])
facility_name = get_facility_name(event_obj["world_event_list"][0]["zone_id"], event_obj["world_event_list"][0]["facility_id"])
zone = get_zone(event_obj["world_event_list"][0]["zone_id"])
result = "The " + faction_name + " defended " + facility_name + ", on " + zone + "."
print result
engine.say(result)
engine.runAndWait()
else:
faction_new_name = get_faction(event_obj["world_event_list"][0]["faction_new"])
faction_old_name = get_faction(event_obj["world_event_list"][0]["faction_old"])
facility_name = get_facility_name(event_obj["world_event_list"][0]["zone_id"], event_obj["world_event_list"][0]["facility_id"])
zone = get_zone(event_obj["world_event_list"][0]["zone_id"])
result = "The " + faction_old_name + " lost control of " + facility_name + " to The " + faction_new_name + ", on " + zone + "."
print result
engine.say(result)
engine.runAndWait()
def speakStats(character_id):
url = "http://census.soe.com/get/ps2-beta/character/" + character_id + "?c:show=certs,experience,name"
r = requests.get(url)
obj = r.json()
name = obj["character_list"][0]["name"]["first"]
til_next_cert = obj["character_list"][0]["certs"]["percentagetonext"]
rank = obj["character_list"][0]["experience"][0]["rank"]
result = name + " is rank " + rank + ", and is " + til_next_cert + " percent of their way to a new cert."
print result
engine.say(result)
engine.runAndWait()
doCheck = 1
speakInterval = 60 * 5 # Every 5 mins
statsInterval = 60 * 60 # Every 60 mins
interval = 60 # Interval to iterate at
lastSpeakTime = time.clock() - speakInterval
lastStatsTime = time.clock() - statsInterval
engine.setProperty('rate', 150)
while doCheck:
# print time.strftime("%H:%M:%S", time.gmtime())
now = time.clock()
if now - lastSpeakTime >= speakInterval:
lastEventOnServer()
lastSpeakTime = time.clock()
if now - lastStatsTime >= statsInterval:
speakStats("5428031585351466737")
lastStatsTime = time.clock()
time.sleep(interval)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment