def checkGroup(api,dbinfo,group,member,origMsg,ingroup=lambda a,b,c,d:True,outgroup=lambda a,b,c,d:True,finalMsg=None,af=0.5): '''checkGroup - Check if a user is in any of the groups specified in group If user is in a group, execute ingroup Else, execute outgroup API Format: {in,out}group(api,db,gid,uid)''' if dbinfo is not None: db = {dbinfo['tName'][0]:sqldb.sqliteDB(dbinfo['fName'],dbinfo['tName'][0])} for i in dbinfo['tName'][1:]: db[i] = sqldb.sqliteDB(db[dbinfo['tName'][0]],i) else: db = None api.query('sendChatAction',{'chat_id':origMsg['chat']['id'],'action':'typing'}) ct = time.time() for item in group: try: data = api.query('getChatMember',{'chat_id':item,'user_id':member},retry=0) if data['status'] in ('kicked','left','restricted'): outgroup(api,db,item,member) else: ingroup(api,db,item,data) except tg.APIError: outgroup(api,db,item,member) time.sleep(af) if time.time()-ct > 4.2: api.query('sendChatAction',{'chat_id':origMsg['chat']['id'],'action':'typing'}) ct = time.time() if finalMsg: api.sendMessage(origMsg['chat']['id'],finalMsg,{'reply_to_message_id':origMsg['message_id']})
def main(args): tmp = sqldb.sqliteDB(args[0],'config') db = (tmp,sqldb.sqliteDB(tmp,'group'),sqldb.sqliteDB(tmp,'warn')) if db[0].getItem('dbver','value') == '1.0': update0(db) if db[0].getItem('dbver','value') == '1.1': update1(db) print("Your database is up-to-date.")
def main(): dbFile = botconfig.db apiKey = botconfig.apiKey db = {'config':sqldb.sqliteDB(dbFile,'config')} if db['config'].getItem('dbver','value') != '1.0': raise tg.APIError('DB','DB Version Mismatch') for item in ('noir','blanc','admin','group'): db[item] = sqldb.sqliteDB(db['config'],item) api = tg.tgapi(apiKey) run(db,api)
def main(): regList = psvdb.psvDB('../Data/registration.psv') newList = psvdb.psvDB('../Data/csgStats.psv') db = sqldb.sqliteDB('../Data/Users.sql','csg') ts = ET.parse('../Data/CSGInfo.xml') notFound = [] nextID = 0 for key in regList.data.keys(): fName = key bName = regList.data[key][0] try: pid = db.searchItem('nickname',base64.b64encode(bName.encode('utf-8')).decode('ascii')) except: notFound.append([fName,bName]) else: cpid = db.getItem(pid,'cpid') setiID = str(nextID) nextID += 1 score = db.getItem(pid,'score') score = score[:score.index('.')] newList.addItem([setiID,cpid,fName,bName,pid,score]) newList.addItem(['header']+newList.data['header']+[ts.find('update_time').text]) print('The following users were not found:') for item in notFound: print(item[0],item[1])
def initiateDB(fName): try: conf = sqldb.sqliteDB(fName, 'config') except sqldb.sqliteDBError: raise APIError('DB', 'Corrupted configuration table') if conf.getItem('dbver', 'value') != '1.0': raise APIError('DB', 'Database schema version is incompatible') try: group = sqldb.sqliteDB(conf.db, 'group') except sqldb.sqliteDBError: raise APIError('DB', 'Corrupted group table') try: warn = sqldb.sqliteDB(conf.db, 'warn') except sqldb.sqliteDBError: raise APIError('DB', 'Corrupted warn table') print('DB File ' + fName + ' loaded.') return (conf, group, warn)
def makeDB(fileName): try: localInfo = open('../Data/SETIInfo.xml', 'r') localTime = localInfo.read().split()[4][13:-14] except: getSETIXML() else: import urllibRequests as ur remoteTime = ur.get('http://setiathome.berkeley.edu/stats/tables.xml' ).split()[4][13:-14] if int(localTime) < int(remoteTime): print('The local SETI users.xml is old, updating...') # getSETIXML() # Now it is safe to assume that the ../Data/SETIUser.xml is up to date. import sqldb try: db = sqldb.sqliteDB(fileName, 'seti') except: sqldb.createSQLiteDB(fileName, ['CPID', 'Nickname', 'Country'], 'seti') db = sqldb.sqliteDB(fileName, 'seti') print('Creating the SETI User SQLite DB...') # Time to parse the whole XML file... import xml.etree.ElementTree as ET tree = ET.iterparse('../Data/SETIUser.xml') flag = False # Remove this later. for (event, elem) in tree: if elem.tag == 'user': cpid = elem.find('cpid').text uid = elem.find('id').text if int(uid) % 10000 == 0: print('Processing uid', uid) uname = base64.b64encode( elem.find('name').text.encode('utf-8')).decode('ascii') country = elem.find('country').text if not country: country = 'International' if flag: # Remove this later db.addItem([uid, cpid, uname, country]) db.updateDB() elif uid == '8703526': flag = True elem.clear() print('SETI User DB was created successfully.')
def makeDB(fileName, projAbbr, webUrl): try: localInfo = open('../Data/' + projAbbr + 'Info.xml', 'r') localTime = localInfo.read().split()[4][13:-14] except: getSETIXML(webUrl, projAbbr) else: import urllibRequests as ur remoteTime = ur.get(webUrl + '/stats/tables.xml').split()[4][13:-14] if int(localTime) < int(remoteTime): print('The local ' + projAbbr + ' users.xml is old, updating...') getSETIXML(webUrl, projAbbr) print('The local ' + projAbbr + ' users.xml is fresh now.') # Now it is safe to assume that the ../Data/SETIUser.xml is up to date. import sqldb try: db = sqldb.sqliteDB(fileName, projAbbr.lower()) except: sqldb.createSQLiteDB(fileName, ['CPID', 'Nickname', 'Country', 'Score'], projAbbr.lower()) db = sqldb.sqliteDB(fileName, projAbbr.lower()) print('Creating the ' + projAbbr + ' User SQLite DB...') # Time to parse the whole XML file... import xml.etree.ElementTree as ET tree = ET.iterparse('../Data/' + projAbbr + 'User.xml') for (event, elem) in tree: if elem.tag == 'user': cpid = elem.find('cpid').text uid = elem.find('id').text if int(uid) % 10000 == 0: print('Processing uid', uid) score = elem.find('total_credit').text uname = elem.find('name').text if not uname: uname = "NoName" uname = base64.b64encode(uname.encode('utf-8')).decode('ascii') country = elem.find('country').text if not country: country = 'International' db.addItem([uid, cpid, uname, country, score]) db.updateDB() elem.clear() print(projAbbr + ' User DB was created successfully.')
def makeDB(fileName,projAbbr,webUrl): try: localInfo = open('../Data/'+projAbbr+'Info.xml','r') localTime = localInfo.read().split()[4][13:-14] except: getSETIXML(webUrl,projAbbr) else: import urllibRequests as ur remoteTime = ur.get(webUrl+'/stats/tables.xml').split()[4][13:-14] if int(localTime) < int(remoteTime): print('The local '+projAbbr+' users.xml is old, updating...') getSETIXML(webUrl,projAbbr) print('The local '+projAbbr+' users.xml is fresh now.') # Now it is safe to assume that the ../Data/SETIUser.xml is up to date. import sqldb try: db = sqldb.sqliteDB(fileName,projAbbr.lower()) except: sqldb.createSQLiteDB(fileName,['CPID','Nickname','Country','Score'],projAbbr.lower()) db = sqldb.sqliteDB(fileName,projAbbr.lower()) print('Creating the '+projAbbr+' User SQLite DB...') # Time to parse the whole XML file... import xml.etree.ElementTree as ET tree = ET.iterparse('../Data/'+projAbbr+'User.xml') for (event,elem) in tree: if elem.tag == 'user': cpid = elem.find('cpid').text uid = elem.find('id').text if int(uid) % 10000 == 0: print('Processing uid',uid) score = elem.find('total_credit').text uname = elem.find('name').text if not uname: uname = "NoName" uname = base64.b64encode(uname.encode('utf-8')).decode('ascii') country = elem.find('country').text if not country: country = 'International' db.addItem([uid,cpid,uname,country,score]) db.updateDB() elem.clear() print(projAbbr+' User DB was created successfully.')
def makeDB(fileName): try: localInfo = open('../Data/SETIInfo.xml','r') localTime = localInfo.read().split()[4][13:-14] except: getSETIXML() else: import urllibRequests as ur remoteTime = ur.get('http://setiathome.berkeley.edu/stats/tables.xml').split()[4][13:-14] if int(localTime) < int(remoteTime): print('The local SETI users.xml is old, updating...') # getSETIXML() # Now it is safe to assume that the ../Data/SETIUser.xml is up to date. import sqldb try: db = sqldb.sqliteDB(fileName,'seti') except: sqldb.createSQLiteDB(fileName,['CPID','Nickname','Country'],'seti') db = sqldb.sqliteDB(fileName,'seti') print('Creating the SETI User SQLite DB...') # Time to parse the whole XML file... import xml.etree.ElementTree as ET tree = ET.iterparse('../Data/SETIUser.xml') flag = False # Remove this later. for (event,elem) in tree: if elem.tag == 'user': cpid = elem.find('cpid').text uid = elem.find('id').text if int(uid) % 10000 == 0: print('Processing uid',uid) uname = base64.b64encode(elem.find('name').text.encode('utf-8')).decode('ascii') country = elem.find('country').text if not country: country = 'International' if flag: # Remove this later db.addItem([uid,cpid,uname,country]) db.updateDB() elif uid == '8703526': flag = True elem.clear() print('SETI User DB was created successfully.')
def main(args): if len(args) == 0 or args[0] in ('-h', '--help', '-?'): print(sys.argv[0] + ' - Update StaphMB DB') print('Synopsis:') print('\t' + sys.argv[0] + ' init.db') exit() tmp = sqldb.sqliteDB(args[0], 'config') db = [tmp, sqldb.sqliteDB(tmp, 'group'), sqldb.sqliteDB(tmp, 'warn')] if db[0].getItem('dbver', 'value') == '1.0': update0(db) if db[0].getItem('dbver', 'value') == '1.1': update1(db) if db[0].getItem('dbver', 'value') == '1.2': update2(db) db.append(sqldb.sqliteDB(tmp, 'admin')) if db[0].getItem('dbver', 'value') == '1.3': update3(db) db.append(sqldb.sqliteDB(tmp, 'auth')) if db[0].getItem('dbver', 'value') == '1.4': update4(db) if db[0].getItem('dbver', 'value') == '1.5': update5(db) if db[0].getItem('dbver', 'value') == '1.6': update6(db) db.append(sqldb.sqliteDB(tmp, 'imgid')) print("Your database is up-to-date.")
def main(args): db = sqldb.sqliteDB(args[0], 'config') db.addItem(['lastid', str(int(db.getItem('lastid', 'value')) + 1)])