コード例 #1
0
def check_wa_status(nat):
    if nat not in nat_is_wa:
        try:
            natxml = None
            try:
                natxml = api_request({"nation": nat, "q": "wa"}, user_agent)
                nat_is_wa[nat] = natxml.find("UNSTATUS").text != "Non-member"
            finally:
                del natxml
            nat_exists[nat] = True
        except CTE:
            nat_is_wa[nat] = False
            nat_exists[nat] = False
    return nat_is_wa[nat]
コード例 #2
0
            finally:
                del natxml
            nat_exists[nat] = True
        except CTE:
            nat_is_wa[nat] = False
            nat_exists[nat] = False
    return nat_is_wa[nat]


def exists(nat):
    if nat not in nat_exists:
        check_wa_status(nat)
    return nat_exists[nat]


wa_xml = api_request({"wa": "1", "q": "members"}, user_agent)

wa_members = wa_xml.find("MEMBERS").text.split(",")

del wa_xml


def page(nat):
    i = wa_members.index(nat)
    return i - i % 15


__page_url__fmts = "http://www.nationstates.net/page=list_nations/un=UN?start=%d"


def page_url(nat):
コード例 #3
0
if( len(argv) < 3 ):
    print "usage: ./zombie_scan <region> <user>"
    print "(user must be a valid identifier of you as required by http://www.nationstates.net/pages/api.html#terms )"
    exit()

region = argv[1]

author = 'Eluvatar'
user = argv[2]

user_agent = "Zombie Scanner by %s being run by %s"%(author, user)

res = []

nations = api_request({'region':region,'q':'nations'},user_agent).find('NATIONS').text.split(':')

for nat in nations:
        try:
            entry = {"name":nat}
            natxml = api_request({'nation':nat,'q':['zombie','name']},user_agent)
            entry["Name"] = natxml.find("NAME").text
            zx = natxml.find('ZOMBIE')
            entry["action"] = zx.find('ZACTION').text
            entry["zombies"] = int(zx.find('ZOMBIES').text)
            entry["survivors"] = int(zx.find('SURVIVORS').text)
            entry["dead"] = int(zx.find('DEAD').text)
            res.append(entry)
        except:
            pass
out    = open('zombie_info.json','w')