Skip to content

Instantly share code, notes, and snippets.

@phenomist
Last active June 10, 2017 19:19
Show Gist options
  • Save phenomist/4110db4f35190fe8ec59cee64123185f to your computer and use it in GitHub Desktop.
Save phenomist/4110db4f35190fe8ec59cee64123185f to your computer and use it in GitHub Desktop.
Python script to download a list of every single building in CA by ID
import requests
f = open("buildinglist.csv", "w")
cookies = {"PHPSESSID":"insert", "phpbb2mysql_data":"cookies",
"phpbb2mysql_sid":"here"} #get your own cookies from inspecting network headers
player = "qwerqwerqwer" #replace with player running it (technically, the player whose cookies are used)
pemp = " Overpowered" #same thing
errorstreak = 0
def sanitize(s):
return s.replace(",","_")
for i in range(16500):
body = requests.get("http://castleage.net/index.php?page=building&id="+str(i), cookies=cookies).text
if "Error" in body:
errorstreak += 1
if errorstreak > 100:
break
else:
errorstreak = 0
try:
content = body.split("table cellspacing=\"1\"")[1].split("/table")[0]
owner = sanitize(content.split("Send ")[1].split(" a mail!")[0])
locx = content.split("<b>")[1].split(" ")[0]
locy = content.split("<b>")[1].split(" ")[2]
buildtype = content.split(":")[1].split(locy)[1].split(" &middot")[0][1:]
name = sanitize(content.split("&middot; ")[1].split("</b>")[0])
empire = sanitize(content.split("empire menu!\">")[1].split("</a>")[0])
f.write(str(i)+","+locx+","+locy+","+owner+","+buildtype+","+name+","+empire+"\n")
except:
pass #it won't work on your own buildings
body = requests.get("http://castleage.net/index.php?page=overview&subtopic=buildings&type=&display=all", cookies=cookies).text
for e in body.split("index.php?page=building&amp;id=")[1:]:
i = e.split("&")[0]
e = e.split("&amp;x=")[1]
locx = e.split("&")[0]
e = e.split("&amp;y=")[1]
locy = e.split("\">")[0]
e = e.split("\">")[1]
buildtype = e.split("&nbsp;")[0]
try:
e = e.split("8C\">")[1]
name = e.split("</f")[0]
except:
name = ""
owner = player
empire = pemp
f.write(str(i)+","+locx+","+locy+","+owner+","+buildtype+","+name+","+empire+"\n")
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment