All pastes #1638015 Raw Edit

eMinistarstvo.py

public unlisted python v1 · immutable
#1638015 ·published 2009-10-22 18:38 UTC
rendered paste body
#! /usr/bin/env python##  Copyright (C) 2009 by Filip Brcic <brcha@gna.org>##  eRepublik app for managing Srpsko Ministarstvo Emigracije##  This program is free software: you can redistribute it and/or modify#  it under the terms of the GNU General Public License as published by#  the Free Software Foundation, either version 3 of the License, or#  (at your option) any later version.##  This program is distributed in the hope that it will be useful,#  but WITHOUT ANY WARRANTY; without even the implied warranty of#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the#  GNU General Public License for more details.##  You should have received a copy of the GNU General Public License#  along with this program.  If not, see <http://www.gnu.org/licenses/>.#from eRepublik import Citizen, Regionimport sysfrom getopt import getoptimport fileinputclass eMinistarstvo:    def __init__(self):        self.start = 0        self.values = []        self.check = None    def parseArgs(self):        opts = getopt(sys.argv[1:], 's=i=c=', ['start=', 'input=', 'check='])        for (o,v) in opts[0]:            if o == '-s' or o == '--start':                self.start = int(v)            elif o == '-i' or o == '--input':                self.loadValues(v)            elif o == '-c' or o == '--check':                self.loadCheck(v)    def loadValues(self, filename):        baseURL = 'http://www.erepublik.com/en/citizen/profile/'        for line in fileinput.input(filename):            if line.startswith(baseURL):                self.values.append(int(line.split(',')[0].replace(baseURL,'')))    def loadCheck(self, filename):        baseURL = 'http://www.erepublik.com/en/citizen/profile/'        self.check = []        for line in fileinput.input(filename):            if line.startswith(baseURL):                split = line.split(',')                split[0] = split[0].replace(baseURL,'')                # We need the ID (1st field) + status (3rd field)                self.check.append((int(split[0]), int(split[2])))    def run(self):        self.parseArgs()        if self.check != None:            map(lambda x: self.checkCitizen(x), self.check)            return 0        bg = Region(635)        rs = Region(639)        ss = Region(640)        cit = Citizen()        citizen_ids = bg.getCitizens() + rs.getCitizens() + ss.getCitizens()        citizen_ids.sort()        for cit_id in citizen_ids:            if not cit_id > self.start: # ignore all older citizens                continue            if cit_id in self.values: # ignore already loaded citizens                continue            cit.loadById(cit_id)            exp = cit.getExperience()            if exp >= 25 and exp < 100 and cit.getCitizenshipId() == 65 and cit.getWellness() >= 29:                skillsum = cit.getManufacturing() + cit.getLand() + cit.getConstructions()                if not (skillsum < 2 and cit.getStrength() < 3):                    print 'http://www.erepublik.com/en/citizen/profile/' + str(cit.getId())    def checkCitizen(self, id_status_tuple):        cit_id = id_status_tuple[0]        cit_st = id_status_tuple[1]        if cit_st == 0:            cit = Citizen().loadById(cit_id)            reg_id = cit.getRegionId()            if not reg_id in [635, 639, 640]:                print str(cit.getId()) + " moved!"def main():    emin = eMinistarstvo()    emin.run()        if __name__ == "__main__":    main()