-
Notifications
You must be signed in to change notification settings - Fork 0
/
sheriffbot.py
69 lines (53 loc) · 2.05 KB
/
sheriffbot.py
1
import copy, datetime, os, sys, timefrom pydc_client import pydc_clientimport loggingdef get_ips(client): done = {} previous_length = 0 with open('ips.csv') as ips_file: for line in ips_file: nick = line.split(',')[0] done[nick] = True previous_length = len(done) logfile = open('log.csv', 'r') ips_file = open("ips.csv", 'a') for line in logfile: last_comma = line.rfind(',') + 1 nick_ip = line[last_comma:] if 'Hub:' in nick_ip: nick = nick_ip.replace('Hub:', '') nick = nick[:nick.find(':')] if nick in client._nicklist and nick not in done: client._searchfor[nick] = True client.connect_remote(nick, False) if "Not Available"!= client._foundips[nick]: done[nick] = True ips_file.write('%s, %s\n' %(nick, client._foundips[nick])) ips_file.close() print 'Processed' print 'Found %d new ips' %(len(done) - previous_length)def filelist_analyse(filename,nick): try: print "Filelist download complete :", nick, filename # Insert TimeStamp into Filename oldfilename = filename[:-4] # ignore the trailing .bz2 now = datetime.datetime.now() now = now.strftime(".%Y-%m-%d-%H-%M-%S.") filename = filename.split(os.sep) filename[-1] = filename[-1].split(".") filename[-1][0] = filename[-1][0][1:] filename[-1] = ".".join(filename[-1][:-2])+now+filename[-1][-2] filename = os.sep.join(filename) os.rename(oldfilename,filename) except OSError: print "OSError in Callback Function.", nick, filenameif __name__=="__main__": config_data = { "mode":True, "name":"NWA", "host":"172.17.23.44","nick":"BigTip","pass":"banana","desc":"","email":"","sharesize":53687091200,"localhost":"172.17.14.98"} c = pydc_client().configure(config_data).link({"mainchat":sys.stderr.write,"debug":[sys.stdout.write,open("debug.txt","w").write,None][2] }).connect("0/1/0"); c._config["overwrite"] = True time.sleep(3); # Wait for the connection to established and session to be verified. # c.cli(); c.connect('1') get_ips(c)"""To share files, manually add them using ~self.filelist_add(<path>) and ~self.filelist_generate()"""