def retrieveUserByHostname(self, hostname): try: self.cursor.execute( """ SELECT id, hostname FROM hostnames WHERE hostname=? """, (hostname, )) except sqlite3.OperationalError: return None else: result = self.cursor.fetchone() if result: user_id = result[0] else: return None try: self.cursor.execute( """ SELECT id, characterName, characterID, keyID, vCode FROM users WHERE id=? """, (user_id, )) except sqlite3.OperationalError: return None else: result = self.cursor.fetchone() if result: return { "characterName": result[1], "characterID": result[2], "keyID": result[3], "vCode": result[4], "apiObject": api.API(keyID=result[3], vCode=result[4], charid=result[2], characterName=result[1]) } else: return None
def index(connection, event, config, evedb, USERS): """ Changes saved settings for your registered user SYNTAX: update [char name] [keyID] [vCode] [old password] (new password) """ #check user sourceHostname = event.source() sourceNick = event.source().split("!")[0] response = USERS.retrieveUserByHostname(sourceHostname) if not response: connection.privmsg(sourceNick, "You are not identified") else: #get args try: charName = " ".join(event.arguments()[0].split()[1:-2]) keyID = event.arguments()[0].split()[-2] vCode = event.arguments()[0].split()[-1] except IndexError: connection.privmsg( sourceNick, "SYNTAX: %supdate [char name] [keyID] [new vCode]" % config["bot"]["prefix"]) else: #check details are correct try: API = api.API(keyID=keyID, vCode=vCode, characterName=charName) API.Account("characters") except api.APIError: connection.privmsg( sourceNick, "Update failed with error: %s" % " ".join( traceback.format_exc().splitlines()[-1].split()[1:])) else: response = USERS.updateUser(charName, keyID, vCode, sourceHostname) if response[0]: USERS.removeHostname(sourceHostname) USERS.addHostname(charName, sourceHostname) connection.privmsg( sourceNick, "Your information was updated successfully") else: connection.privmsg( sourceNick, "Update failed with error: %s" % response[1])
def lookupAlt(self, vCode, keyID, characterName, altName): API = api.API(keyID=keyID, vCode=vCode) characters = API.Account("characters") if characterName in characters.keys() and altName in characters.keys(): try: self.cursor.execute( """ SELECT id, characterName, characterID, keyID, vCode FROM users WHERE characterName=? AND keyID=? AND vCode=? """, (altName, keyID, vCode)) except sqlite3.OperationalError: return None else: result = self.cursor.fetchone() if not result: return None else: return True else: return None
def checkAPIurls(self): try: API = api.API() CACHE = cache.CACHE() tablenames = CACHE.getTableNames() conn = sqlite3.connect("var/cache/cache.db") cursor = conn.cursor() for tablename in tablenames: if tablename != "rss": cursor.execute(""" SELECT url, expireTime, requestName FROM %s """ % tablename) rows = cursor.fetchall() for url, expireTime, requestName in rows: if time.time() > expireTime: #remove old entry CACHE.requestXML(url, postdata=None) xml = urllib2.urlopen(url).read() #check for error try: API._errorCheck(xml) except api.APIError: #this will prune out erroneous API calls from the cache pass else: new_expireTime = API._getCachedUntil(xml) CACHE.insertXML(url, requestName, xml, new_expireTime, postdata=None) except: print "Error in scheduler thread (checkAPIurls):" traceback.print_exc()
You should have received a copy of the GNU General Public License. If not, see <http://www.gnu.org/licenses/>. AUTHORS: mountainpenguin <*****@*****.**> Ghent <*****@*****.**> petllama <*****@*****.**> """ import locale from modules import api from modules.misc import functions API = api.API() def index(connection, event, config, EVE, userdb): locale.setlocale(locale.LC_ALL, config["core"]["locale"]) try: systemName = event.arguments()[0].split()[1] except IndexError: connection.privmsg( event.target(), "Syntax is: %skills [system name]" % config["bot"]["prefix"]) else: response = API.Map("kills", systemName) if not response: connection.privmsg(event.target(), "System '%s' is unknown to me" % systemName)
import sys from requests.packages import urllib3 from requests.packages.urllib3.exceptions import InsecureRequestWarning from modules import api, result if __name__ == "__main__": urllib3.disable_warnings(InsecureRequestWarning) try: qf_api = api.API(config_path="config.ini", config_section="QF_API") test_cycle_id = qf_api.create_test_cycle() results = result.parse_xml("results/result.xml") qf_api.post_test_results(results=results, test_cycle_id=test_cycle_id) except Exception as e: print(e) sys.exit(1)
def createUser(self, keyID, vCode, characterName, password, hostname, hashpassword=None): try: API = api.API(keyID=keyID, vCode=vCode, characterName=characterName) except api.APIError as error: return (False, error) else: if API.CHAR_ID: characters = API.Account("characters") if not hashpassword: hashpassword = hashlib.md5(password).hexdigest() randomid = "".join([ random.choice(string.ascii_letters + string.digits) for x in range(20) ]) #first check if user exists def alreadyexists(characterName, keyID): self.cursor.execute( """ SELECT id,characterName,keyID FROM users WHERE characterName = ? """, (characterName, )) check = self.cursor.fetchone() if check: return (False, 'Entry already exists') else: return (True, '') response = alreadyexists(characterName, keyID) if not response[0]: return response self.cursor.execute( """ INSERT INTO users (id, characterName, characterID, keyID, vCode, password) VALUES (?, ?, ?, ?, ?, ?) """, (randomid, characterName, API.CHAR_ID, keyID, vCode, hashpassword)) #add alternate characters also for characterName_alt in characters.keys(): if alreadyexists(characterName_alt, keyID)[0]: randomid_alt = "".join([ random.choice(string.ascii_letters + string.digits) for x in range(20) ]) charID_alt = characters[characterName_alt][ "characterID"] self.cursor.execute( """ INSERT INTO users (id, characterName, characterID, keyID, vCode, password) VALUES (?, ?, ?, ?, ?, ?) """, (randomid_alt, characterName_alt, charID_alt, keyID, vCode, hashpassword)) self.removeHostname(hostname) self.cursor.execute( """ INSERT INTO hostnames (id, hostname) VALUES (?, ?) """, (randomid, hostname)) self.conn.commit() return (True, '') else: return (False, 'Invalid details')