def mkzip(self, zipname, attr): if 'flac' == attr: files = [getattr(file, attr) for file in self.files if getattr(file, attr) and file.lossless] else: files = [getattr(file, attr) for file in self.files if getattr(file, attr)] if len(files): zipname = zip.zip(zipname, files + [file.name for file in self.files if not file.is_audio()]) if zipname: self.files.append(File(zipname))
def test_head(self): xs_cases = [ [], [5], [3, 8], [1, 12, 5, 32, 9, 1, 3, 17], ] ys_cases = [ [], [''], ['a', 'b'], ['vrrp', 'meep', 'baboon', 'trilobyte'], ] cases = [(xs, ys) for xs in xs_cases for ys in ys_cases] for xs, ys in cases: with self.subTest(xs=xs, ys=ys): found = zip(xs, ys) n = min(len(xs), len(ys)) self.assertEqual([v[0] for v in found], xs[:n]) self.assertEqual([v[1] for v in found], ys[:n])
def s_t(template, enrol=1): # defining variables len_template = len(template) template_id = 255 nbr_temp_hdr_bytes = 28 nbr_temp_ftr_bytes = 2 bytes_per_minutae = 6 max_seg_chars = 130 number_minutae = int( (len_template - 2 * (nbr_temp_hdr_bytes + nbr_temp_ftr_bytes)) / (bytes_per_minutae * 2)) if template[:8] == "464d5200": template = template[8:] i = 0 while (template[-1] == '0' and i < 9): template = template[:-1] i += 1 template += str(i) template = zip.zip(template) template = template.replace("00", '?') len_template = len(template) # segment structure in bytes - segment_number, template_id, minutae_count seg_bytes = {"seg_nbr": 1, "temp_id": 1, "min_cnt": 1} #build template segments temp_segments = [] seg_indx = 0 ttl_char_ctr = 0 seg_1_max_len = max_seg_chars - 2 * ( seg_bytes["seg_nbr"] + seg_bytes["temp_id"] + seg_bytes["min_cnt"]) # only 1 segment required if seg_1_max_len > len(template): temp_segments.append(template) ttl_char_ctr += len(temp_segments[0]) seg_indx += 1 #multiple segments required else: temp_segments.append(template[0:seg_1_max_len]) seg_indx += 1 seg_max_len = max_seg_chars - 2 * (seg_bytes["seg_nbr"] + seg_bytes["temp_id"]) ttl_char_ctr += len(temp_segments[0]) while ttl_char_ctr < len_template: if seg_max_len > len_template - ttl_char_ctr: temp_segments.append(template[ttl_char_ctr:]) else: temp_segments.append(template[ttl_char_ctr:(ttl_char_ctr + seg_max_len)]) ttl_char_ctr += len(temp_segments[seg_indx]) seg_indx += 1 nbr_segments = seg_indx print str(nbr_segments) + " SMS" for i in range(0, nbr_segments): header = format(i + 1, '01x') + format(nbr_segments, '01x') + format( template_id, '02x') if i == 0: header += format((number_minutae * 2 - 1) * enrol, '02x') temp_segments[i] = header + temp_segments[i] return (temp_segments)
def weather(message_response): #Extracts Data for i in range(len(message_response['output']['entities'])): #Extracts City if message_response['output']['entities'][i]['entity']=='location_city': city_name=message_response['output']['entities'][i]['value'] #Extracts Zip if message_response['output']['entities'][i]['entity']=='sys-number': #Verifies Zip if len(message_response['output']['entities'][i]['value'])==5: potential_zip_code=message_response['output']['entities'][i]['value'] output=zip(potential_zip_code) if output!='00': zip_code=potential_zip_code city_name=output #Extracts State if message_response['output']['entities'][i]['entity']=='location_state': state_name=message_response['output']['entities'][i]['value'] state_id=state(state_name) #Converts To State ID #Extracts Date if message_response['output']['entities'][i]['entity']=='sys-date': forecast_date=message_response['output']['entities'][i]['value'] #Formats Forecast Date forecast_date=datetime.strptime(forecast_date,'%Y-%m-%d') #Obtains Current Time in UTC UTC=pytz.utc current_date=datetime.date(datetime.now(UTC)) #Calculates Day Difference difference=forecast_date.date()-current_date numbers=re.findall('[-]?\d+',str(difference)) days=int(numbers[0])+1 #Adjusts 1 To Be The Current Day #Deletes Invalid Days if days==1: del days elif days<1: del days print("Don't Look Back!") return elif days>16: del days print('Forecast Up To 15 Days Ahead') return #Assigns Used Variables To Null if 'city_name' in locals() or 'city_name' in globals(): city_name=city_name else: city_name='00' if 'zip_code' in locals() or 'zip_code' in globals(): zip_code=zip_code else: zip_code='00' if 'state_id' in locals() or 'state_id' in globals(): state_id=state_id else: state_id='00' API_Key='9af3cf2f443d4faea1e866c4e765b2f7' #Assigns Base URL By Current Weather/Forecast if 'days' in locals() or 'days' in globals(): Base_URL='https://api.weatherbit.io/v2.0/forecast/daily?' payload={'key':API_Key,'units':'S','days':days} else: Base_URL='https://api.weatherbit.io/v2.0/current?' payload={'key':API_Key,'units':'S'} #Creates Complete URL With Data if zip_code!='00': Complete_URL=Base_URL + 'postal_code=' + zip_code + '&key=' + API_Key elif city_name!='00': if state_id!='00': Complete_URL=Base_URL + 'city=' + city_name + ',' + state_id + '&key=' + API_Key else: Complete_URL=Base_URL + 'city=' + city_name + '&key=' + API_Key else: print('Too Little Information!') try: response=requests.get(Complete_URL,params=payload) #Sends Request weather_response=response.json() #Formats Response #print(json.dumps(weather_response,indent=2)) #Returns Weather Data if 'days' in locals() or 'days' in globals(): i=-1 date=str(weather_response['data'][i]['valid_date']) else: i=0 date=str(weather_response['data'][i]['datetime'])[0:10] temp_K=round(weather_response['data'][i]['temp'],2) temp_C=round(temp_K-273.15,2) temp_F=round(temp_C*9/5+32,2) wind=round(weather_response['data'][i]['wind_spd'],2) rain=round(weather_response['data'][i]['precip'],2) snow=round(weather_response['data'][i]['snow'],2) clouds=weather_response['data'][i]['clouds'] humidity=weather_response['data'][i]['rh'] description=weather_response['data'][i]['weather']['description'] icon=weather_response['data'][i]['weather']['icon'] print('Date: ' + date) print('Temperature: ' + str(temp_K) + 'K ' + \ str(temp_C) + '°C ' + \ str(temp_F) + '°F') print('Wind: ' + str(wind) + 'm/s') print('Rain: ' + str(rain) + 'mm/hr') print('Snow: ' + str(snow) + 'mm/hr') print('Clouds: ' + str(clouds) + '%') print('Humidity: ' + str(humidity) + '%') print('Description: ' + description) #image=Image.open(icon + '.png') #image.show() except: print('City Not Found') #Deletes Variables if 'days' in locals() or 'days' in globals(): del city_name,zip_code,state_id,days else: del city_name,zip_code,state_id
def s_t(template, enrol= 1): # defining variables len_template = len(template) template_id = 255 nbr_temp_hdr_bytes = 28 nbr_temp_ftr_bytes = 2 bytes_per_minutae = 6 max_seg_chars = 130 number_minutae = int( (len_template - 2*(nbr_temp_hdr_bytes + nbr_temp_ftr_bytes)) /(bytes_per_minutae*2) ) if template[:8] == "464d5200": template = template[8:] i = 0 while (template[-1] == '0' and i < 9): template = template[:-1] i += 1 template += str(i) template = zip.zip(template) template = template.replace("00", '?') len_template = len(template) # segment structure in bytes - segment_number, template_id, minutae_count seg_bytes = { "seg_nbr":1, "temp_id":1, "min_cnt":1 } #build template segments temp_segments = [] seg_indx = 0 ttl_char_ctr = 0 seg_1_max_len = max_seg_chars - 2*(seg_bytes["seg_nbr"] + seg_bytes["temp_id"] + seg_bytes["min_cnt"]) # only 1 segment required if seg_1_max_len > len(template): temp_segments.append(template) ttl_char_ctr += len(temp_segments[0]) seg_indx += 1 #multiple segments required else: temp_segments.append(template[0:seg_1_max_len]) seg_indx += 1 seg_max_len = max_seg_chars - 2*(seg_bytes["seg_nbr"] + seg_bytes["temp_id"]) ttl_char_ctr += len(temp_segments[0]) while ttl_char_ctr < len_template: if seg_max_len > len_template - ttl_char_ctr: temp_segments.append(template[ttl_char_ctr:]) else: temp_segments.append(template[ttl_char_ctr : (ttl_char_ctr + seg_max_len) ]) ttl_char_ctr += len(temp_segments[seg_indx]) seg_indx += 1 nbr_segments = seg_indx print str(nbr_segments) + " SMS" for i in range(0, nbr_segments): header = format(i+1, '01x') + format(nbr_segments, '01x') + format(template_id, '02x') if i == 0: header += format((number_minutae * 2 - 1) * enrol, '02x') temp_segments[i] = header + temp_segments[i] return(temp_segments)
origin_src = 'remote' if re.match(regex, args.source) else 'local' origin_dst = 'remote' if re.match(regex, args.destination) else 'local' if __name__ == '__main__': print 'golem at work' sftp_src = remote.sftpclient(args.source) if origin_src == 'remote' else None sftp_dst = remote.sftpclient(args.destination) if origin_dst == 'remote' else None root_src = remote.info(args.source).root if origin_src == 'remote' else os.path.abspath(args.source) root_dst = remote.info(args.destination).root if origin_dst == 'remote' else os.path.abspath(args.destination) ignore = ignore(root_src + os.sep + 'config.json', sftp_src) if args.backup: print 'backuping folder ' + root_dst zip(root_dst, paths(root_dst, ignore, sftp_dst), args.backup, sftp_dst) for file_src in paths(root_src, ignore, sftp_src): file_dst = file_src.replace(root_src, root_dst) if utils.isdir(file_src, sftp_src): print 'creating folder ' + file_dst utils.mkdir(file_dst, sftp_dst) else: data_src = copy(file_src, sftp_src) if exists(file_dst): data_dst = copy(file_dst, sftp_dst) md5_data_src = md5(data_src).digest() md5_data_dst = md5(data_dst).digest() if md5_data_src == md5_data_dst: print 'unchanged ' + file_dst else: