Best Python code snippet using avocado_python
test.py
Source:test.py
1from ast import Not2import re3total_result=[None,(None,7,10,12,17,23,28,34),(None,20,24,29,31,33,34,35),4 (None,2,7,8,11,14,23,31),(None,12,13,22,23,24,28,29),(None,1,3,4,5,16,21,28),5 (None,5,15,19,23,30,34,35),(None,1,3,5,7,27,29,33),(None,2,21,28,29,30,32,36),6 (None,3,4,15,23,27,30,36),(None,1,2,3,6,24,28,30)]7def up_result() :8 """å¤æ°total_result(ä»ã¾ã§ã®å½é¸æ°å)ãæ´æ°ãããæ¬æ°åã®ã¿9 """10 n=len(total_result)11 print("第 {} åã®çµæãå
¥åãã¾ããä¸æ¢ã¯'q'".format(n),"\n")12 result=[None]13 for i in range(1,8):14 m=input("第 {} æ°åãå
¥åãã¦ãã ãã".format(i))15 if m == "q":16 break17 result.append(m)18 if len(result) == 8:19 result=tuple(result)20 total_result.append(result)21up_result()22#æ´æ°ããtotal_resultããã¡ã¤ã«ã«æ¸ãè¾¼ã¾ãªããã23#ifã«ã¼ãã®ä¸ã§1~37以å¤ãå
¥åããã¨ãã¯ã¨ã©ã¼ãåºã(continue?)24#æ°åãæé ã«ä¸¦ã¹æ¿ããå¿
è¦ãã25class Anal_column:26 """ç´è¿ï½åã®ç¬¬ï½æ°åããããã解æãã27 """28 def __init__(self,n,m):29 self.n=n*-130 self.m=m31 32 def appear_column(self):33 """åºç¾é »åº¦ã調ã¹ã"""34 column=[]35 for i in range(self.n,0):36 column.append(total_result[i])37def appear_column(n,m):38 """ç´è¿ï½åã®ç¬¬ï½æ°åã®åºç¾é »åº¦ã調ã¹ã39 å
é æ°åã®è©ä¾¡ã«ä½¿ã"""40 n=n*(-1)41 column=[]#ç´è¿ï½åã®ç¬¬ï½æ°åã®ãªã¹ã42 for i in range(n,0):43 column.append(total_result[i][m])44 print(column)45 appear=[None,[1,0],[2,0],[3,0],[4,0],[5,0],[6,0],[7,0],46 [8,0],[9,0],[10,0],[11,0],[12,0],[13,0],[14,0],47 [15,0],[16,0],[17,0],[18,0],[19,0],[20,0],[21,0],48 [22,0],[23,0],[24,0],[25,0],[26,0],[27,0],[28,0],49 [29,0],[30,0],[31,0],[32,0],[33,0],[34,0],[35,0],50 [36,0],[37,0]]#1~37ã«åºç¾åæ°ãå²ãå½ã¦ãããã®ãªã¹ã51 for val in column:52 appear[val][1] += 153 appear.pop(0)#Noneãæ··å¨ãã¦ãã¨sortã§ããªã54 #ç¡åé¢æ°lambdaã®å¼æ°xã¯appearã®åè¦ç´ ãæ»ãå¤:åè¦ç´ ã®indexï¼ã§ã½ã¼ããã55 appear.sort(key=lambda x: x[1],reverse=True)56 print(appear)57appear_column(10,1)58def appear_all(n):59 """ç´è¿ï½åã®ãã¹ã¦ã®ä½ç½®ã§ã®åºç¾é »åº¦ã調ã¹ã"""60 n=n*-161 recent_result=total_result[n:]62 print(recent_result)#ç´è¿ï½åã®å½é¸çªå·ã®ãªã¹ã63 appear=[None,[1,0],[2,0],[3,0],[4,0],[5,0],[6,0],[7,0],64 [8,0],[9,0],[10,0],[11,0],[12,0],[13,0],[14,0],65 [15,0],[16,0],[17,0],[18,0],[19,0],[20,0],[21,0],66 [22,0],[23,0],[24,0],[25,0],[26,0],[27,0],[28,0],67 [29,0],[30,0],[31,0],[32,0],[33,0],[34,0],[35,0],68 [36,0],[37,0]]#1~37ã«åºç¾åæ°ãå²ãå½ã¦ãããã®ãªã¹ã69 for val in recent_result:70 for i in range(1,8):71 appear[val[i]][1]+=172 appear.pop(0)73 appear.sort(key=lambda x: x[1],reverse=True)74 print(appear)75appear_all(2)76def int_column(n,m):77 """第ï½åã®ç¬¬ï½æ°åã®å¤ã¨ãã®ç¬¬ï½æ°åã®åã«ãããåºç¾ééå¤ã調ã¹ã78 å
é æ°åã®è©ä¾¡ã«ä½¿ã"""79 n_result=total_result[n][m]80 m_column=[]#第ï½æ°åã®ãªã¹ã81 for i in range(1,n+1):82 m_column.append(total_result[i][m])83 m_column.reverse()#æ°ããã»ãããã¸ä¸¦ã³æ¿ã84 m_column[0]=None#ã¤ã³ããã¯ã¹ï¼ã¯ç¬¬ï½åãã®ãã®ãªã®ã§ï¼®ï¼¯ï¼®ï¼¥ã§åãã85 if n_result in m_column:86 int_n=m_column.index(n_result)#æ°åããªãã£ãæã®å¦çèãã87 else :88 int_n=089 print(n_result)90 print(m_column)91 print(int_n)92int_column(7,2)93def int_all(n,m):94 """第ï½åã®ç¬¬ï½æ°åã®å¤ã¨ãã¹ã¦ã®ä½ç½®ã§ã®åºç¾ééå¤ã調ã¹ã"""95 n_result=total_result[n][m]96 sub_total_result=total_result[:n]97 sub_reverse_result=reversed(sub_total_result)#æ°ããã»ãããã¸ä¸¦ã³æ¿ã98 sub_reverse_result=list(sub_reverse_result)#ã¤ãã¬ã¼ã¿ããªã¹ãå99 int_n=0100 for i in range(n-1):101 if n_result in sub_reverse_result[i]:102 int_n=i+1103 break104 print(total_result)105 print(n_result)106 print(sub_reverse_result)107 print(int_n)108int_all(9,1)109def next_number(n,m):110 """第ï½åã®å½é¸çªå·ã®ç¬¬ï½æ°åãã次åã«ãã®ç¬¬ï½æ°åã®åã«111 åºãæ°åã調ã¹ã"""112 n_result=total_result[n][m]113 appear=[None,[1,0],[2,0],[3,0],[4,0],[5,0],[6,0],[7,0],114 [8,0],[9,0],[10,0],[11,0],[12,0],[13,0],[14,0],115 [15,0],[16,0],[17,0],[18,0],[19,0],[20,0],[21,0],116 [22,0],[23,0],[24,0],[25,0],[26,0],[27,0],[28,0],117 [29,0],[30,0],[31,0],[32,0],[33,0],[34,0],[35,0],118 [36,0],[37,0]]#1~37ã«åºç¾åæ°ãå²ãå½ã¦ãããã®ãªã¹ã119 for i in range(1,len(total_result)-1):#len()-1:ææ°ã®çµæã¯é¤ã(次åã¯ãªããã)120 if n_result == total_result[i][m]:121 next=total_result[i+1][m]122 appear[next][1]+=1123 appear.pop(0)124 appear.sort(key=lambda x: x[1],reverse=True)125 print(appear)126next_number(10,2)127def present_one_digit(n):128 """ç´è¿ï½åã®ä¸ä¸æ¡æ°åï¼ï¼ï½ï¼ï¼ã¨ãã®ä½ç½®ï¼ç¬¬ï½æ°åã¨ãã¦ï¼ã129 調ã¹ã"""130 m=n*-1131 recent_result=total_result[m:]132 print(recent_result)#ç´è¿ï½åã®å½é¸çªå·ã®ãªã¹ã133 recent_one_digit=[None]134 for j,val in enumerate(recent_result):135 str_line=[]136 for i in range(1,8):137 str_rize=str(val[i])#æåå138 str_rize=str_rize[-1]#ä¸ä¸æ¡ãåãåºã(æå¾ã®ã¤ã³ããã¯ã¹)139 str_line.append(str_rize)140 recent_one_digit.append(str_line)141 recent_one_digit[j+1].insert(0,None)142 print(recent_one_digit)143 checker=["0","1","2","3","4","5","6","7","8","9"]144 one_digit_posi=[None]145 for j in range(1,n+1):146 sub_posi=[["0"],["1"],["2"],["3"],["4"],["5"],["6"],["7"],["8"],["9"]]147 for i,val in enumerate(recent_one_digit[j]):148 for check in checker:149 if check == val:150 sub_posi[checker.index(check)].append(i)151 one_digit_posi.append(sub_posi)#ã¤ã³ããã¯ã¹ï¼ã¯ä¸ä¸æ¡æ°åã®å¤ãã¤ã³ããã¯ã¹ï¼ä»¥éã¯ä½ç½®(第ï½æ°åã¨ãã¦)152 print(one_digit_posi)153 return one_digit_posi154present_one_digit(2)155def sort_pre_one_digit(s):156 """é¢æ°present_one_digitã§å¾ããããªã¹ã(å¼æ°)ãã½ã¼ããã«ãã157 ãªã¹ãã®ãããªãã¥ã¼ã¿ãã«ãªãã¸ã§ã¯ãã®å ´åãb=a(åç
§æ¸¡ã)ã¨ããã¨158 bæãã¯aã®å¤æ´ããaæãã¯bã«ãåæ ããã¦ãã¾ãã159 (æååãã¿ãã«ã®ãããªã¤ãã¥ã¼ã¿ãã«ã¯æ°ã«ããªãã§ï¼¯ï¼«ï¼160 ãªã®ã§é¢æ°ãåãããé¢æ°ãåãã¦ãé¢æ°ã®æ»ãå¤(ãªã¹ã)ãå¤æ°ã«ä»£å
¥(åç
§æ¸¡ã)ãã¦161 使ãã¾ãããããã¡ãå½±é¿ãåãããå½±é¿ãåããªãããã«ã¯ä¸ã
ã¡ã¢ãªã«ãã¼ããå¥ãªãã¸ã§ã¯ãã«ãã162 ã¾ã¨ã163 å¤æ°ã«ä»£å
¥(åç
§æ¸¡ã)ï¼ãã¥ã¼ã¿ãã«ãªãã¸ã§ã¯ã(è¦ç´ ãã¤ãã¥ã¼ã¿ãã«ã§ã)ã¯å¤æ´ãå
ã®ãªãã¸ã§ã¯ãã«åæ 164 æµ
ãã³ãã¼(ã¹ã©ã¤ã¹ã¨ãcopyã¡ã½ãã)ï¼è¦ç´ ããã¥ã¼ã¿ãã«ãªã(ãªã¹ãã®è¦ç´ ããªã¹ãã¨ã)ã¯å½±é¿ããã165 æ·±ãã³ãã¼(deepcopyã¡ã½ãã)ï¼å¤§ä¸å¤«ï¼166 åèï¼https://snowtree-injune.com/2018/07/17/post-565/ã¨ã167 https://note.nkmk.me/python-copy-deepcopy/168 """169 #âãã大äºãtotal_resultãå å·¥ãããªã¹ãã®å¤æ°ãä½ããããå å·¥ããã¨total_resultãå¤ãã£ã¦ãã¾ãï¼170 #ä»ã¾ã§ä½ã£ãé¢æ°ãã§ãã¯ã®äº 171 #total_resultã¯è¦ç´ ãã¿ãã«ãªã®ã§ã¹ã©ã¤ã¹ãã¦ä½ã£ããªãã¸ã§ã¯ãã¯å¤§ä¸å¤«ï¼172 #one_digit_posiã¯è¦ç´ ããªã¹ããªã®ã§ããããä½ã£ããªãã¸ã§ã¯ããå å·¥ããã¨173 #å
ã®ãªãã¸ã§ã¯ããå½±é¿ãåãããdeepcopyãé¢æ°ãåãã174 s.pop(0)175 for i in range(len(s)):176 s[i].sort(key=lambda x: len(x),reverse=True)177 for i,val in enumerate(s):178 for j,val2 in enumerate(val):179 if len(val2)==2:180 break181 s[i]=s[i][:j]182 print(s)183sort_pre_one_digit(present_one_digit(6))184def next_one_digit(n):185 """第ï½åã®å½é¸çªå·ã®ä¸ä¸æ¡æ°åã次åã«ã©ã®ä¸ä¸æ¡æ°åãåºããã186 調ã¹ãã"""187 n_result=total_result[n:n+2]188 n_result.insert(0,None)189 print(n_result)#第ï½åã®å½é¸çªå·ã®ãªã¹ã190 n_one_digit=[None]191 for j,val in enumerate(n_result):192 if val == None:193 continue194 str_line=[]195 for i in range(1,8):196 str_rize=str(val[i])#æåå197 str_rize=str_rize[-1]#ä¸ä¸æ¡ãåãåºã(æå¾ã®ã¤ã³ããã¯ã¹)198 str_line.append(str_rize)199 n_one_digit.append(str_line)200 n_one_digit[j].insert(0,None)201 print(n_one_digit)202 next_list=[]203 for j ,val1 in enumerate(n_one_digit[1]):204 if val1 == None:205 continue206 for i ,val2 in enumerate(n_one_digit[2]):207 if val2 == None:208 continue209 if val1 == val2 :210 t=(val1,n_result[1][j],j,n_result[2][i],i)211 #ä¸ä¸æ¡æ°å,ï½åã®æ°åï¼ï½åã®ä½ç½®ï¼ç¬¬ï½æ°åï¼,次åï¼ï½ï¼ï¼ï¼ã®æ°åï¼æ¬¡åï¼ï½ï¼ï¼ï¼ã®ä½ç½®ï¼ç¬¬ï½æ°åï¼212 next_list.append(t)213 print(next_list)214next_one_digit(2)215#ååã®å½é¸çªå·ã®æ°åããããåºã¦ããä¸ä¸æ¡æ°åã調ã¹ãé¢æ°ãä½ã216#next_one_digitãè¤æ°åç¹°ãè¿ãè¯ãåºã¦ããæ°åã調ã¹ãâãã¨ã§è²·ãç®ã217#ã ãã¢ã«ã´ãªãºã ãèããæ218#present_one_digit&sortããå°ãç°¡åã«ãªããªãããã£ã¦ã¿ãã219#ã§ããï¼ä¸ã®present_one_digitã¨sort_pre_one_digitãã²ã¨ã¤ã«ã¾ã¨ããï¼220def present_one_digit2(n):221 """ç´è¿ï½åã®ä¸ä¸æ¡æ°åï¼ï¼ï½ï¼ï¼ã¨ãã®ä½ç½®ï¼ç¬¬ï½æ°åã¨ãã¦ï¼ã222 調ã¹ã"""223 m=n*-1224 recent_result=total_result[m:]225 recent_result.insert(0,None)226 print(recent_result)#ç´è¿ï½åã®å½é¸çªå·ã®ãªã¹ã227 recent_one_digit=[None]228 for j,val in enumerate(recent_result):229 if val == None:230 continue231 str_line=[]232 for i in range(1,8):233 str_rize=str(val[i])#æåå234 str_rize=str_rize[-1]#ä¸ä¸æ¡ãåãåºã(æå¾ã®ã¤ã³ããã¯ã¹)235 str_line.append(str_rize)236 recent_one_digit.append(str_line)237 recent_one_digit[j].insert(0,None)238 print(recent_one_digit)239 checker=["0","1","2","3","4","5","6","7","8","9"]240 one_digit_posi=[None]241 for j in range(1,n+1):242 sub_posi=[]243 sub_posi2=[]244 for i,val in enumerate(recent_one_digit[j]):245 if val == None:246 continue247 for h in checker:248 if h == val:249 l=[h,recent_result[j][i],i]#ä¸ä¸æ¡æ°åï¼ãã®æ°åï¼ä½ç½®ï¼ç¬¬ï½æ°åã¨ãã¦ï¼250 sub_posi.append(l)251 print(sub_posi)252 #ããã«sub_posiã®ã¤ã³ããã¯ã¹ï¼ãè©ä¾¡ãã¦åºç¾åæ°ãï¼æªæºã¯æ¶ãã³ã¼ããå
¥ãã253 l2=[x[0] for x in sub_posi]254 print(l2)255 l2=[val2 for val2 in l2 if l2.count(val2)>1]256 print(l2)257 l3=[]258 l2=[x for x in l2 if x not in l3 and not l3.append(x)]259 print(l2)260 for m in l2:261 for val3 in sub_posi:262 if val3[0] == m:263 sub_posi2.append(val3)264 one_digit_posi.append(sub_posi2)265 return one_digit_posi266present_one_digit2(3)267def next_conti_number(n):268 """第ï½åã®å½é¸çªå·ã®ä¸ãã次åãç¶ç¶ãã¦åºãæ°åã調ã¹ã269 ï¼å¼ã£å¼µãæ°åï¼"""270 n_result=total_result[n:n+2]271 n_result.insert(0,None)272 print(n_result)#第ï½åã®å½é¸çªå·ã®ãªã¹ã273 274 next_list=[]275 for j,val1 in enumerate(n_result[1]):276 if val1 == None:277 continue278 for i,val2 in enumerate(n_result[2]):279 if val2 == None:280 continue281 if val1 == val2 :282 t=(str(val1),n_result[1][j],j,n_result[2][i],i)283 #ç¶ç¶æ°å,ï½åã®æ°åï¼ï½åã®ä½ç½®ï¼ç¬¬ï½æ°åï¼,次åï¼ï½ï¼ï¼ï¼ã®æ°åï¼æ¬¡åï¼ï½ï¼ï¼ï¼ã®ä½ç½®ï¼ç¬¬ï½æ°åï¼284 #ä¸ã§ã¤ã³ããã¯ã¹ï¼ãï¼ã¯ãããªããã¨ããããnext_one_digitã®æ»ãå¤ã¨å½¢ãåããã¦ãã285 next_list.append(t)286 print(next_list)287next_conti_number(9)288def present_serial_number(n):289 """第ï½åã®é£ç¶æ°åï¼ï½ï¼ï½ï¼ï¼ã¨ãã®ä½ç½®ï¼ç¬¬ï½ï¼ï½ï¼æ°åã¨ãã¦ï¼ã290 調ã¹ã"""291 n_result=total_result[n]292 print(n_result)#第ï½åã®å½é¸çªå·ã®ãªã¹ã293 serial_list=[]294 for i in range(1,7):295 if n_result[i] == n_result[i+1]-1:296 val=[n_result[i],n_result[i+1],i,i+1]#ï½ï¼ï½ï¼ï¼ï½ï¼ï½ï¼297 serial_list.append(val)298 print(serial_list)299present_serial_number(1)300def next_shift_number(n):301 """第ï½åã®å½é¸çªå·ã®æ¬æ°åãã次åã«ï¼ï¼ã®æ°å(r_shift=å¾æ°å)ã302 ï¼ï¼ã®æ°åï¼l_shift=åæ°åï¼ã調ã¹ã303 ï¼åæ°åã»å¾æ°åï¼"""304 n_result=total_result[n:n+2]305 n_result.insert(0,None)306 print(n_result)#第ï½åã®å½é¸çªå·ã®ãªã¹ã307 r_shift_list=[]308 l_shift_list=[]309 for j,val1 in enumerate(n_result[1]):310 if val1 == None:311 continue312 for i,val2 in enumerate(n_result[2]):313 if val2 == None:314 continue315 if val1+1 == val2 :316 t=(n_result[1][j],j,n_result[2][i],i)317 #ï½åã®æ°åï¼ï½åã®ä½ç½®ï¼ç¬¬ï½æ°åï¼,次åï¼ï½ï¼ï¼ï¼ã®æ°åï¼æ¬¡åï¼ï½ï¼ï¼ï¼ã®ä½ç½®ï¼ç¬¬ï½æ°åï¼318 r_shift_list.append(t)319 if val1-1 == val2:320 u=(n_result[1][j],j,n_result[2][i],i)321 l_shift_list.append(u)322 print(r_shift_list)323 print(l_shift_list)...
api.py
Source:api.py
1from application.mongo import Connection2from flask import jsonify3class APIManager(object):4 5 @staticmethod6 def index():7 """8 API Manager Index Page9 :return:10 """11 return jsonify(12 status=200,13 detail="Welcome to Social Manager API",14 services=[{"source": "Twitter", "url": "/api/v1/twitter"}]15 ), 20016class TwitterAPI(object):17 18 @staticmethod19 def index():20 """21 Twitter API Index Page22 :return:23 """24 return jsonify(25 status=200,26 detail="Twitter API Index",27 services=[28 {29 "name": "Listener",30 "url": "/api/v1/twitter/search/{KEYWORD-TO-SEARCH}",31 "util": "/api/v1/twitter/keywords"32 },33 {34 "name": "Tweet Discover",35 "url": "/api/v1/twitter/tweets/{USER-TO-DISCOVER}",36 "util": "/api/v1/twitter/users"37 },38 {39 "name": "Friends Discover",40 "url": "/api/v1/twitter/friends/{USER-TO-DISCOVER}",41 "util": "/api/v1/twitter/users"42 },43 {44 "name": "Follower Discover",45 "url": "/api/v1/twitter/followers/{USER-TO-DISCOVER}",46 "util": "/api/v1/twitter/users"47 }48 ]49 ), 20050 51 @staticmethod52 def get_keywords():53 """54 Return the list of all available keywords55 :return: Json56 """57 return jsonify(status=200,58 keywords=Connection.Instance().db.twitter.find({"source": "listener"}).distinct("keywords")), 20059 60 @staticmethod61 def search(keyword, page=1):62 """63 Get all tweets from a given keyword with pagination support.64 :param keyword: Keyword to search65 :param page: Page Number66 :return:67 """68 try:69 page = int(page) if int(page) > 0 else 170 except:71 page = 172 n_result = 1073 total_result = Connection.Instance().db.twitter.find({"keywords": keyword, "source": "listener"}).count()74 result = list(Connection.Instance().db.twitter.find(75 {76 "keywords": keyword,77 "source": "listener"78 },79 {80 "_id": False,81 "created": False,82 "keywords": False,83 "source": False84 }).skip((page-1)*n_result).limit(n_result))85 86 page_size = len(result)87 88 return jsonify(89 total_result=total_result,90 status=200,91 page_size=page_size,92 page=page,93 result=[data['data'] for data in result],94 next="/api/v1/twitter/search/python/%s" % str(page + 1) if page_size == n_result else None,95 before="/api/v1/twitter/search/python/%s" % str(page - 1) if page > 1 else None96 ), 20097 @staticmethod98 def get_users():99 """100 Return list of users fetched101 :return: Json102 """103 return jsonify(status=200,104 users=Connection.Instance().db.twitter.find({"user": {"$ne": None}}).distinct("user")), 200105 @staticmethod106 def get_tweets(user, page=1):107 """108 Return List of tweets from a specific user109 :param user: User Screen Name110 :param page: Page Number111 :return:112 """113 total_result = Connection.Instance().db.twitter.find({"user": user, "source": "collector"}).count()114 try:115 page = int(page) if int(page) > 0 else 1116 except:117 page = 1118 n_result = 10119 result = list(Connection.Instance().db.twitter.find(120 {121 "source": "collector",122 "user": user123 }124 ).skip((page-1)*n_result).limit(n_result))125 126 page_size = len(result)127 return jsonify(128 total_result=total_result,129 status=200,130 page_size=page_size,131 page=page,132 result=[data['data'] for data in result],133 next="/api/v1/twitter/tweets/%s/%s" % (user, str(page + 1)) if page_size == n_result else None,134 before="/api/v1/twitter/tweets/%s/%s" % (user, str(page - 1)) if page > 1 else None135 ), 200136 @staticmethod137 def get_followers(user, page=1):138 """139 Return List of followers of a specific user140 :param user: User Screen Name141 :param page: Page Number142 :return:143 """144 total_result = Connection.Instance().db.twitter.find({"user": user, "source": "follower"}).count()145 try:146 page = int(page) if int(page) > 0 else 1147 except:148 page = 1149 n_result = 10150 result = list(Connection.Instance().db.twitter.find(151 {152 "source": "follower",153 "user": user154 }155 ).skip((page - 1) * n_result).limit(n_result))156 page_size = len(result)157 return jsonify(158 total_result=total_result,159 status=200,160 page_size=page_size,161 page=page,162 result=[data['data'] for data in result],163 next="/api/v1/twitter/followers/%s/%s" % (user, str(page + 1)) if page_size == n_result else None,164 before="/api/v1/twitter/followers/%s/%s" % (user, str(page - 1)) if page > 1 else None165 ), 200166 @staticmethod167 def get_friends(user, page=1):168 """169 Return List of friends of a specific user170 :param user: User Screen Name171 :param page: Page Number172 :return:173 """174 total_result = Connection.Instance().db.twitter.find({"user": user, "source": "friends"}).count()175 try:176 page = int(page) if int(page) > 0 else 1177 except:178 page = 1179 n_result = 10180 result = list(Connection.Instance().db.twitter.find(181 {182 "source": "friends",183 "user": user184 }185 ).skip((page - 1) * n_result).limit(n_result))186 187 page_size = len(result)188 189 return jsonify(190 total_result=total_result,191 status=200,192 page_size=page_size,193 page=page,194 result=[data['data'] for data in result],195 next="/api/v1/twitter/friends/%s/%s" % (user, str(page + 1)) if page_size == n_result else None,196 before="/api/v1/twitter/friends/%s/%s" % (user, str(page - 1)) if page > 1 else None...
find_addends_recu.py
Source:find_addends_recu.py
1# -*- coding: utf-8 -*-2# from .find_addends_utils import tol2side_x_eq_y3# # from find_addends_utils import tol2side_x_eq_y4from dramkit.find_addends.find_addends_utils import tol2side_x_eq_y5def find_addends_recu(tgt_sum, alts, max_idx, choseds=[], results=[],6 tol_below=0.0, tol_above=0.0, n_result=None,7 keep_order=True):8 '''9 | éå½æ¹æ³ï¼ä»ç»å®çå表altsä¸éåè¥å¹²ä¸ªæ°ä¹åææ¥è¿tgt_sum10 | ä¼ç¹: å¯å¨å®æ°èå´å
æ±è§£ï¼æ²¡ææ£è´ææ´æ°éå¶ï¼è½å¤è¿åææå¯è¡è§£ï¼ç论ä¸ï¼11 | 缺ç¹: åéå½æ·±åº¦éå¶ï¼alts太é¿å°±æ æ³æ±è§£ï¼æ²¡æå¯è¡è§£çæ
åµä¸ä¸è½è¿åç¸å¯¹æä¼è§£ï¼12 Parameters13 ----------14 tgt_sum : float, int15 ç®æ å16 alts : list17 å¤éæ°å表18 max_idx : int19 ä»ç´¢å¼max_idxå¤å¼å§ä»åå¾åæç´¢ï¼åå§å¼ä¸è¬è®¾ä¸ºaltsçæ大索å¼20 choseds : list21 é¢éä¸çå¤éæ°ï¼åå§å¼é»è®¤ä¸ºç©º22 results : list23 å·²åå¨çææç»æï¼åå§å¼é»è®¤ä¸ºç©º24 tol_below : float25 ä¸ç误差ï¼è¥ç®æ ååå»å½ååå°äºçäºtol_belowï¼å为å¯è¡è§£ï¼é»è®¤ä¸º0.026 tol_above : tol27 ä¸ç误差ï¼è¥å½åååå»ç®æ åå°äºçäºbol_aboveï¼å为å¯è¡è§£ï¼é»è®¤ä¸º0.028 n_result : int, None29 è¿åçå¯è¡è§£ä¸ªæ°éå¶ï¼å½resultsçé¿åº¦å¤§äºn_resultæ¶è¿åresults30 keep_order : bool31 æ¯å¦ä¿ç»æä¸å¤éæ°çè¿å
¥é¡ºåºä¸altsä¸ç顺åºä¸è´ï¼é»è®¤æ¯32 Returns33 -------34 results : list35 ææå¯è½ç解å表36 References37 ----------38 https://blog.csdn.net/mandagod/article/details/7958875339 '''40 if n_result is None:41 if max_idx < 0:42 return results43 else:44 if len(results) > n_result-1 or max_idx < 0:45 return results46 result = [] # ä¿åä¸ä¸ªå¯è¡è§£47 # 满足误差çéæå³çæ¾å°ä¸ä¸ªå¯è¡è§£48 if tol2side_x_eq_y(alts[max_idx], tgt_sum, tol_below, tol_above):49 result.append(alts[max_idx])50 if keep_order:51 choseds = choseds[::-1] # 对chosedséåºï¼ä¿è¯é¡ºåºï¼52 result += choseds53 choseds = choseds[::-1] # æ¢å¤é¡ºåº54 else:55 result += choseds56 results.append(result)57 # éä¸max_idxä¹å继ç»éå½58 choseds.append(alts[max_idx])59 results = find_addends_recu(tgt_sum-alts[max_idx], alts, max_idx-1,60 choseds=choseds, results=results,61 tol_below=tol_below, tol_above=tol_above,62 n_result=n_result, keep_order=keep_order)63 # ä¸émax_idx继ç»éå½64 del choseds[-1]65 results = find_addends_recu(tgt_sum, alts, max_idx-1, choseds=choseds,66 results=results, tol_below=tol_below,67 tol_above=tol_above, n_result=n_result,68 keep_order=keep_order)69 return results70if __name__ == '__main__':71 import time72 start_time = time.time()73 tgt_sum = 22 + 21 + 4.174 alts = [22, 15, 14, 13, 7, 6.1, 5, 21.5, 100]75 # alts = [100, 99, 98, 98.2, 6, 5, 3, -20, -25]76 # tgt_sum = 78.277 # alts = [200, 107, 100, 99, 98, 6, 5, 3, -1, -20, -25]78 # tgt_sum = 100 + 6 - 2579 # alts = [-900, 901, 800, 600, -400, 402]80 # tgt_sum = 181 # alts = [100, -100, -105, -102, -25, -30, -1]82 # tgt_sum = -2683 alts = [10, 9, 8, 7, 6, 5]84 tgt_sum = 1785 # alts = [10, 9, 8, -7, -6, -5]86 # tgt_sum = 387 # alts = [10, 7, 6, 3]88 # tgt_sum = 1889 # alts = [10, 7, 6, 3]90 # tgt_sum = 1291 max_idx = len(alts) - 192 choseds = []93 results = []94 tol_below = 0.000195 tol_above = 0.000196 n_result = None97 keep_order = True98 results = find_addends_recu(tgt_sum, alts, max_idx, choseds=choseds,99 results=results, tol_below=tol_below,100 tol_above=tol_above, n_result=n_result,101 keep_order=keep_order)102 print('å¯è½çåºå:')103 for result in results:104 print(result, end='')105 s = sum(result)106 print('\nå:', s, '\nç®æ å:', tgt_sum, '\nå·®:', tgt_sum-s, end='\n\n')...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!