# How to use n_result method in avocado

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...`

`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')...`

## 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.