def WriteFile(self, name=''): """ Syntax: WriteFile([name= ]) Purpose: Write information contained in an ADPAA object to a properly- formatted NASA ASCII file. Input: 'name' - optional argument to set the filename of the file being written to (uses ADPAA class attribute 'name' otherwise) Output: nothing """ if (name == '') & (self.name == ''): print("ERROR: Cannot write to file because class attribute 'name'"+\ " is not set.") return if (name == '') & (self.name != ''): name = self.name # Set number of variables (self.NV) according to the length of the # long name array (self.VNAME). self.NV = len(self.VNAME) # Check that all data has proper data types and is formatted properly. self.__check_data(name) # Call the WriteFile method. WriteFile(self, name)
def start_download (self): dpath = self.downman.config.get_property ('DefaultDownloadDirectory') self.location = os.path.join (dpath, re.search ('([^\/]*)$', self.url).group (1)) rfrom = None if os.path.exists (self.location): s = os.stat (self.location) if s.st_size == self.total: self.set_state (STATE_COMPLETED) return if s.st_size == self.downloaded: rfrom = self.downloaded self.tfile = WriteFile (self.url, self.location, rfrom=rfrom) self.tfile.completed_cb = self.download_completed self.tfile.progress_cb = self.download_progress self.tfile.start () self.status = 'Downloading...' self.set_state (STATE_DOWNLOADING)
def start_get_info (self): self.tfile = HttpNoBody (self.url) self.tfile.completed_cb = self.handle_info_completed self.tfile.start ()
class HttpDownload (Download): pdtotal = -1 def __init__ (self, url, downman): self.url = url self.name = re.search ('([^\/]*)$', self.url).group (1) self.downman = downman self.speed = downman.speedlimit.create_download () def start_get_info (self): self.tfile = HttpNoBody (self.url) self.tfile.completed_cb = self.handle_info_completed self.tfile.start () def handle_info_completed (self, tfile): self.total = tfile.size if tfile.response_code >= 200 and tfile.response_code < 400: self.status = 'Online' self.set_state (STATE_INFO_COMPLETED) else: self.status = 'Offline' self.set_state (STATE_NOT_FOUND) def start_download (self): dpath = self.downman.config.get_property ('DefaultDownloadDirectory') self.location = os.path.join (dpath, re.search ('([^\/]*)$', self.url).group (1)) rfrom = None if os.path.exists (self.location): s = os.stat (self.location) if s.st_size == self.total: self.set_state (STATE_COMPLETED) return if s.st_size == self.downloaded: rfrom = self.downloaded self.tfile = WriteFile (self.url, self.location, rfrom=rfrom) self.tfile.completed_cb = self.download_completed self.tfile.progress_cb = self.download_progress self.tfile.start () self.status = 'Downloading...' self.set_state (STATE_DOWNLOADING) def download_progress (self, dt, dd, ut, ud): self.downloaded = dd self.total = dt diff = dd - self.pdtotal self.pdtotal = dd val = self.speed.update_downloaded (diff) self.speed.wait (val) def download_completed (self, wfile): self.status = 'Download Complete' self.set_state (STATE_COMPLETED) def startup (self, data): self.name = data['name'] self.url = data['url'] self.downloaded = float (data['downloaded']) self.total = float (data['total']) self.state = int (data['state']) self.location = data['location'] def shutdown (self): data = {} if self.state == STATE_DOWNLOADING: self.tfile.close () self.state = STATE_QUEUED elif self.state == STATE_WAITING: self.timeout.cancel () self.state = STATE_QUEUED elif self.state == STATE_INFO or self.state == STATE_INFO_COMPLETED: self.tfile.close () return data['name'] = self.name data['url'] = self.url data['downloaded'] = str (self.downloaded) data['total'] = str (self.total) data['state'] = str (self.state) data['match'] = 'http' data['location'] = self.location return data
user_rank = 0 t1 = time.time() test = Account() while(True): if(test.login(account_list[0][0],account_list[0][1])): break init_time = time.time() #to_be_searched = [1995234631] #to_be_searched = [5102872939] to_be_searched = read_users("to_be_searched.txt") searched = read_users("searched.txt") #to_be_searched = [3737537255] searched = [] blogcrawler = BlogCrawler() writefile = WriteFile() f = open("count.txt","r") line = f.readline() line = line.strip() sumcount = int(line) while(len(to_be_searched) > 0): t2 = time.time() all_time = t2-init_time # if(all_time>(3600*3)): # break delta_t = t2-t1 print "user_time: ",delta_t print "all_time: ", all_time if(delta_t> 300):