How to use _line method in localstack

Best Python code snippet using localstack_python

data_vector.py

Source:data_vector.py Github

copy

Full Screen

1import sys2reload(sys)3import pickle4sys.setdefaultencoding('utf8')5x = []6y = []7_data = {}8_yData = {}9max_loud = -50.010min_loud = 0.011music_db = file('Music_DB.txt','r')12movie_db = file('Movie_DB.txt','r')13brand_db = open('Brand_DB.txt','r')14#making features15for a in music_db:16 if (a.split(':')[1].strip()=='None'):17 continue18 if(a.split(':')[0]=='artist'):19 _data[a.split(':')[1].strip()]=120 elif(a.split(':')[0]=='song_type'):21 song_type = a.split(':')[1].split(',')22 for b in song_type:23 _data[b.strip()]=024 elif(a.split(':')[0]=='artist_terms'):25 art_term = a.split(':')[1].split(',')26 for b in art_term:27 _data[b.strip()]=028for a in movie_db:29 if(a.split(':')[0]=='director'):30 director = a.split(':')[1].split(',')31 for b in director:32 _data[b.strip()]=033 elif(a.split(':')[0]=='stars'):34 stars = a.split(':')[1].split(',')35 for b in stars:36 _data[b.strip()]=037 elif(a.split(':')[0]=='genres'):38 genres = a.split(':')[1].split(',')39 for b in genres:40 _data[b.strip()]=041#making features which need to be separated into 10 parts42for a in range(0,10):43 string = 'energy:'+str(a)44 _data[string]=045 string = 'liveness:'+str(a)46 _data[string]=047 string = 'loudness:'+str(a)48 _data[string]=049 string = 'tempo:'+str(a)50 _data[string]=051 string = 'speechiness:'+str(a)52 _data[string]=053 string = 'acousticness:'+str(a)54 _data[string]=055 string = 'danceability:'+str(a)56 _data[string]=057 string = 'instrumentalness:'+str(a)58 _data[string]=059 string = 'valeance:'+str(a)60 _data[string]=061 string = 'song_hotttnesss:'+str(a)62 _data[string]=063 string = 'votes:'+str(a)64 _data[string]=065 string = 'rate:'+str(a)66 _data[string]=067if '' in _data:68 del _data['']69if '\n' in _data:70 del _data['\n']71print len(_data)72#y73for line in brand_db:74 _yData[line.strip()] = 075#pickle.dump(_yData,open('y_vector','wb'))76#search element(movie, music) in list77samples = open('training.txt','r')78#format: title1 title2 title3 .... 79for sample in samples:80 _yData = dict.fromkeys(_yData,0)81 _data = dict.fromkeys(_data, 0)82 answer = sample.split(',,')[1].strip()83 sample = sample.split(',,')[0].split(',')84 _yData[answer] = 185 for a in sample:86 music_db.close()87 movie_db.close()88 music_db = file('Music_DB.txt','r')89 movie_db = file('Movie_DB.txt','r')90 if 'movie_' in a:91 a = a.split('movie_')[1]92 for line in movie_db:93 if 'title' in line and a == line.split('title:')[1].strip():94 _line = movie_db.next()95 else:96 continue97 while(_line.split(':')[0].strip()!='title'):98 if(_line.split(':')[0]=='rating'):99 string = 'rate:'+str(int(float(_line.split(':')[1].replace('\n',''))))100 if string.strip() in _data:101 _data[string.strip()]=1102 elif(_line.split(':')[0]=='director'):103 director = _line.split(':')[1].split(',')104 for c in director:105 if c.strip() in _data:106 _data[c.strip()]=1107 elif(_line.split(':')[0]=='stars'):108 stars = _line.split(':')[1].split(',')109 for c in stars:110 if c.strip() in _data:111 _data[c.strip()]=1112 elif(_line.split(':')[0]=='genres'):113 genres = _line.split(':')[1].split(',')114 for c in genres:115 if c.strip() in _data:116 _data[c.strip()]=1117 #votes: 5103 ~ 1447826118 elif _line.split(':')[0] == 'votes' :119 votes = float(_line.split(':')[1].replace(',',''))120 votes = votes - 5103121 votes = int(votes/1442723)122 #print votes123 string = 'votes:' + str(votes)124 #if string.strip() in _data:125 _data[string.strip()] = 1126 _line = movie_db.next()127 #if a is song title128 else:129 for line in music_db:130 if not line:131 break132 if 'title' in line and str(a) == line.split('title:')[1].strip():133 _line = music_db.next()134 while(_line.split(':')[0].strip()!='title'):135 if(_line.split(':')[0]=='artist'):136 string = _line.split(':')[1].strip()137 if string in _data:138 _data[string]=1139 elif(_line.split(':')[0]=='energy'):140 ene = float(_line.split(':')[1].strip())141 string = 'energy:'+(str)((int)(ene/0.1))142 if string in _data:143 _data[string]=1144 elif(_line.split(':')[0]=='liveness'):145 live = float(_line.split(':')[1].strip())146 string = 'liveness:'+(str)((int)(live/0.1))147 if string in _data:148 _data[string]=1149 elif(_line.split(':')[0]=='tempo'):150 tempo = int(float(_line.split(':')[1].strip()))-65151 tempo /= 15152 string = 'tempo:'+str(tempo)153 if string in _data:154 _data[string]=1155 elif(_line.split(':')[0]=='speechiness'):156 if _line.split(':')[1].strip() == 'None':157 a = 0.1158 else:159 a = float(_line.split(':')[1].strip())160 string = 'speechiness:'+(str)((int)(a/0.1))161 if string in _data:162 _data[string]=1163 elif(_line.split(':')[0]=='acousticness'):164 a = float(_line.split(':')[1].strip())165 string = 'acousticness:'+(str)((int)(a/0.1))166 if string in _data:167 _data[string]=1168 elif(_line.split(':')[0]=='danceability'):169 a = float(_line.split(':')[1].strip())170 string = 'danceability:'+(str)((int)(a/0.1))171 if string in _data:172 _data[string]=1173 elif(_line.split(':')[0]=='instrumentalness'):174 a = float(_line.split(':')[1].strip())175 string = 'instrumentalness:'+(str)((int)(a/0.1))176 if string in _data:177 _data[string]=1178 elif(_line.split(':')[0]=='loudness'):179 a = float(_line.split(':')[1].strip())+31180 string = 'loudness:'+str((int)(a/3.0))181 if string in _data:182 _data[string]=1183 elif(_line.split(':')[0]=='valence'):184 a = float(_line.split(':')[1].strip())185 string = 'valeance:'+(str)((int)(a/0.1))186 if string in _data:187 _data[string]=1188 elif(_line.split(':')[0]=='song_hotttnesss'):189 a = float(_line.split(':')[1].strip())-0.67190 string = 'song_hotttnesss:'+(str)((int)(a/0.03))191 if string in _data:192 _data[string]=1193 elif(_line.split(':')[0]=='song_type' or _line.split(':')[0]=='artist_terms'):194 a = _line.split(':')[1].split(',')195 for b in a:196 if b.strip() in _data:197 _data[b.strip()]=1198 _line = music_db.next()199 if '\n' in _data:200 del _data['\n']201 if '' in _data:202 del _data['']203 x.append(_data)204 y.append(_yData)205#x,y will be the list of vector206#write x,y to file207x_f = open('x.p','wb')208y_f = open('y.p','wb')209pickle.dump(x,x_f)...

Full Screen

Full Screen

Application.py

Source:Application.py Github

copy

Full Screen

1from instagram.client import InstagramAPI2import requests3from BeautifulSoup import BeautifulSoup4import sys5import locale6import re7import pickle8import numpy as np9reload(sys)10sys.setdefaultencoding('utf8')11access_token='1085114028.582f029.208ffc1f880049b49b96db01f78e049b'12api=InstagramAPI(access_token=access_token)13client_id='582f02988f5b48baa669fedc9d51fb06'14#get tags data from files15tags_dic={}16music_tags=open('music_tag','r')17for line in music_tags:18 title=line.split('::')[0].strip()19 tags=line.split('::')[1].strip().split(' ')20 tags_dic[title]=tags21movie_tags=open('movie_tag','r')22for line in movie_tags:23 title='movie_'+line.split('::')[0].strip()24 tags=line.split('::')[1].strip().split(' ')25 tags_dic[title]=tags26 27 28 29from sklearn.svm import SVC30from sklearn.externals import joblib31clf = joblib.load('SVM.pkl') 32_data = pickle.load(open('vector.p','rb'))33y = pickle.load(open('y_vector','rb'))34y = y.keys()35while True:36 username=raw_input('What is your instagram UserName? :')37 if username=='q':38 break39 #get user id from username40 url='https://api.instagram.com/v1/users/search?q='+username+'&client_id='+client_id41 result=requests.get(url).json()42 data=result['data']43 for datum in data:44 if datum['username']==username:45 print datum['username']46 user_id=datum['id']47 print user_id48 break49 #get contents from user50 #temp id51 #user_id='453076946'52 url_user='https://api.instagram.com/v1/users/'+user_id+'/media/recent/?client_id='+client_id53 #print url_user54 user_tags=[]55 temp=[]56 check_list=['listening','music','listeningto','nowlisteningto']57 result_user=requests.get(url_user).json()58 while True:59 if 'data' not in result_user:60 next_url=result_user['pagination']61 next_url=next_url['next_url']62 result_user=requests.get(next_url).json() 63 continue64 data_user=result_user['data']65 66 for i in data_user: 67 if any(map(lambda v:v in check_list,i['tags'])):68 #print i['tags']69 for j in i['tags']:70 if j not in user_tags:71 user_tags.append(j)72 #if i['tags'] not in user_tags:73 # user_tags.append(i['tags'])74 else:75 for k in i['tags']:76 if 'movie' in k:77 for l in i['tags']:78 if l not in user_tags:79 user_tags.append(l)80 break81 next_url=result_user['pagination']82 if 'next_url' not in next_url:83 break84 next_url=next_url['next_url']85 result_user=requests.get(next_url).json()86 87 88 #find valid contents from tags89 valid_tag=[]90 91 for user_tag_item in user_tags:92 is_found=093 for title, tags in tags_dic.iteritems():94 if is_found==1:95 break96 for tag_item in tags:97 if user_tag_item==tag_item:98 if title not in valid_tag:99 valid_tag.append(title)100 is_found=1101 break102 print valid_tag103 for sample in valid_tag:104 _data = dict.fromkeys(_data,0)105 for a in sample:106 music_db = file('Music_DB.txt','r')107 movie_db = file('Movie_DB.txt','r')108 if 'movie_' in a:109 a = a.split('movie_')[1]110 for line in movie_db:111 if 'title' in line and a == line.split('title:')[1].strip():112 _line = movie_db.next()113 else:114 continue115 while(_line.split(':')[0].strip()!='title'):116 if(_line.split(':')[0]=='rating'):117 string = 'rate:'+str(int(float(_line.split(':')[1].replace('\n',''))))118 if string.strip() in _data:119 _data[string.strip()]=1120 elif(_line.split(':')[0]=='director'):121 director = _line.split(':')[1].split(',')122 for c in director:123 if c.strip() in _data:124 _data[c.strip()]=1125 elif(_line.split(':')[0]=='stars'):126 stars = _line.split(':')[1].split(',')127 for c in stars:128 if c.strip() in _data:129 _data[c.strip()]=1130 elif(_line.split(':')[0]=='genres'):131 genres = _line.split(':')[1].split(',')132 for c in genres:133 if c.strip() in _data:134 _data[c.strip()]=1135 #votes: 5103 ~ 1419284136 elif _line.split(':')[0] == 'votes' :137 votes = float(_line.split(':')[1].replace(',',''))138 votes = votes - 5103139 votes = int(votes/141418)140 #print votes141 string = 'votes:' + str(votes)142 #if string.strip() in _data:143 _data[string.strip()] = 1144 _line = movie_db.next()145 #if a is song title146 else:147 for line in music_db:148 if 'title' in line and str(a) == line.split('title:')[1].strip():149 _line = music_db.next()150 while(_line.split(':')[0].strip()!='title'):151 if(_line.split(':')[0]=='artist'):152 string = _line.split(':')[1].strip()153 if string in _data:154 _data[string]=1155 elif(_line.split(':')[0]=='energy'):156 ene = float(_line.split(':')[1].strip())157 string = 'energy:'+(str)((int)(ene/0.1))158 if string in _data:159 _data[string]=1160 elif(_line.split(':')[0]=='liveness'):161 live = float(_line.split(':')[1].strip())162 string = 'liveness:'+(str)((int)(live/0.1))163 if string in _data:164 _data[string]=1165 elif(_line.split(':')[0]=='tempo'):166 tempo = int(float(_line.split(':')[1].strip()))-65167 tempo /= 15168 string = 'tempo:'+str(tempo)169 if string in _data:170 _data[string]=1171 elif(_line.split(':')[0]=='speechiness'):172 a = float(_line.split(':')[1].strip())173 string = 'speechiness:'+(str)((int)(a/0.1))174 if string in _data:175 _data[string]=1176 elif(_line.split(':')[0]=='acousticness'):177 a = float(_line.split(':')[1].strip())178 string = 'acousticness:'+(str)((int)(a/0.1))179 if string in _data:180 _data[string]=1181 elif(_line.split(':')[0]=='danceability'):182 a = float(_line.split(':')[1].strip())183 string = 'danceability:'+(str)((int)(a/0.1))184 if string in _data:185 _data[string]=1186 elif(_line.split(':')[0]=='instrumentalness'):187 a = float(_line.split(':')[1].strip())188 string = 'instrumentalness:'+(str)((int)(a/0.1))189 if string in _data:190 _data[string]=1191 elif(_line.split(':')[0]=='loudness'):192 a = float(_line.split(':')[1].strip())+31193 string = 'loudness:'+str((int)(a/3.0))194 if string in _data:195 _data[string]=1196 elif(_line.split(':')[0]=='valence'):197 a = float(_line.split(':')[1].strip())198 string = 'valeance:'+(str)((int)(a/0.1))199 if string in _data:200 _data[string]=1201 elif(_line.split(':')[0]=='song_hotttnesss'):202 a = float(_line.split(':')[1].strip())-0.67203 string = 'song_hotttnesss:'+(str)((int)(a/0.03))204 if string in _data:205 _data[string]=1206 elif(_line.split(':')[0]=='song_type' or _line.split(':')[0]=='artist_terms'):207 a = _line.split(':')[1].split(',')208 for b in a:209 if b.strip() in _data:210 _data[b.strip()]=1211 _line = music_db.next()212 if '\n' in _data:213 del _data['\n']214 if '' in _data:215 del _data['']216 x = np.array([_data.values()])217 y_index = clf.predict(x)...

Full Screen

Full Screen

2-1.py

Source:2-1.py Github

copy

Full Screen

1#!/usr/bin/env python32import csv3DATA_DIR = "data/"4def main():5 """Main function."""6 provinces = {}7 with open(DATA_DIR + "省区域.csv", "r", encoding="utf-8-sig") as in_file:8 for _line in csv.reader(in_file):9 province = dict(name=_line[1])10 provinces[_line[0]] = province11 citys = {}12 with open(DATA_DIR + "市区域.csv", "r", encoding="utf-8-sig") as in_file:13 for _line in csv.reader(in_file):14 try:15 _ = provinces[_line[2]]16 city = dict(name=_line[1], belong=_line[2])17 citys[_line[0]] = city18 except KeyError:19 continue20 countys = {}21 with open(DATA_DIR + "县区区域.csv", "r", encoding="utf-8-sig") as in_file:22 for _line in csv.reader(in_file):23 try:24 _ = citys[_line[2]]25 county = dict(name=_line[1], belong=_line[2])26 countys[_line[0]] = county27 except KeyError:28 continue29 sites_by_name = {}30 with open(DATA_DIR + "基站.csv", "r", encoding="utf-8-sig") as in_file:31 for _line in csv.reader(in_file):32 try:33 _ = countys[_line[3]]34 site = dict(site_id=_line[0], belong=_line[3],35 stat=_line[4])36 sites_by_name[_line[1]] = site37 except KeyError:38 continue39 faults = []40 with open(DATA_DIR + "告警.csv", "r", encoding="utf-8-sig") as in_file:41 for _line in csv.reader(in_file):42 try:43 site = sites_by_name[_line[4]]44 site_id = site['site_id']45 stat = site['stat']46 county = site['belong']47 city = countys[county]['belong']48 province = citys[city]['belong']49 except KeyError:50 continue51 fault = (_line[0], _line[1], _line[2], _line[3], _line[4],52 site_id, stat, provinces[province]['name'],53 citys[city]['name'], countys[county]['name'])54 faults.append(fault)55 with open(DATA_DIR + "标准化告警.csv", "w", encoding="utf-8-sig") \56 as in_file:57 csv_writer = csv.writer(in_file)58 csv_writer.writerows(faults)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful