Best Python code snippet using tempest_python
mongo_import_data.py
Source:mongo_import_data.py
1#coding=utf82import datetime3import hashlib4import random5import sys6import pymongo7from bson.objectid import ObjectId8MONGO_HOST = '123.56.8.91'9MONGO_PORT = 2701710MONGO_DBNAME = 'iHealth'11MONGO_AUTHDB = 'iHealth'12MONGO_USER = 'admin'13MONGO_PWD = 'admin123'14def MD5(s):15 '''对å符串sè¿è¡md5å å¯ï¼å¹¶è¿å'''16 m = hashlib.md5()17 m.update(s)18 return m.hexdigest()19# è¿æ¥æ°æ®åº20client = pymongo.MongoClient('mongodb://%s:%s@%s:%d/%s'%(MONGO_USER,MONGO_PWD,MONGO_HOST,MONGO_PORT,MONGO_AUTHDB))21# åæ¢æ°æ®åº22db = client[MONGO_DBNAME]23# æ¸
é¤éå24# db.articles.drop()25db.users.drop()26# è·åéå27articles = db.articles28users = db.users29# æå
¥æ°æ®30# å建md5对象31# m = hashlib.md5()32# æå
¥ article éåæ°æ®33# èµè®¯æ é¢ï¼title34# åå¸æ¶é´ï¼pubdate35# åå¸äººï¼username*36# å
容ï¼content37# print 'æå
¥ articles éåæ°æ®â¦â¦'38# article_list = []39# article_list.append({40# 'title' : 'è·æ¥æ¶åºç°è¿3大信å·ï¼ä¸å®è¦å½å¿ï¼å¯è½æ¯çæ»åå
ï¼',41# 'category' : 'å
»ç常è¯',42# 'read' : 0,43# 'upvote' : 0,44# 'publisher' : 'ä¸åå
»çç½',45# 'publisher_src' : 'http://www.cnys.com/',46# 'href' : 'http://www.cnys.com/zixun/74403.html',47# 'pubdate' : datetime.datetime.now(),48# 'img' : 'http://img.cnys.com/upload/picture/2017/10-19/Z08l2d.gif',49# 'intro' : '''è¿å¹´å
¨æ°çè·ï¼é©¬ææ¾èµäºå¼å±å¾å¦ç«å¦è¼ã50# è¿æ¬æ¯å¥½äºï¼å´åçäºä¼¤å¿äºâââ平常没ç
没çâçé壮年ï¼è·çè·çå°±åä¸çæ»äºã51# ''',52# 'content' : '''53# <div class="reads">54# <p>è¿å¹´å
¨æ°çè·ï¼é©¬ææ¾èµäºå¼å±å¾å¦ç«å¦è¼ã</p><p>è¿æ¬æ¯å¥½äºï¼å´åçäºä¼¤å¿äºâââ平常没ç
没çâçé壮年ï¼è·çè·çå°±åä¸çæ»äºã</p><h3><strong>è·æ¥çæ»ï¼è¿æ¯æä¹åäº?</strong></h3><p>é壮年çæ»å¤§å¤å 为å¿èçé®é¢ââå å¿ç
ãå¿å¾å¤±å¸¸ãå
天æ§å¿èç
çã</p><p>åå ï¼æå¿èç
ï¼èªå·±å´ä¸ç¥é</p><p>è¿å¨çæ»è
å¤æå å¿ç
ï¼è¿æ¯è¿å¨çæ»ç¬¬ä¸ç
å ï¼åªæ¯ä»èªå·±ä¸ç¥éã</p><center><p align="center"><img src="http://img.cnys.com/upload/picture/2017/10-19/Z08l2d.gif" alt=""></p></center><p>å¦ä»å å¿ç
åç
å¹´é¾å¤§å¤§æåï¼äºä¸åå²çå å¿ç
æ£è
å¾å¤ï¼å 为饮é£ãæ½çãååæ¹é¢çåå ã</p><p>å
¶ä¸ï¼å¾å¤äººå¹³æ¶å³ä½¿æä¸èæï¼ä¹ä¸è§å¾æ¯å¿èé®é¢ï¼æ´ä¸ä¼å»æ£æ¥ï¼è¿å°±çä¸äºè¿å¨çæ»çéæ£ã</p><p><strong>ä¿¡å·1ï¼ è¸é¨åè¿«æ+è¿å¨åå é</strong></p><p>è¸é¨æåè¿«æï¼å°±æ¯è¸é·ãå®ä¼å¨è¿å¨å(å
æ¬å¿«èµ°ãä¸æ¥¼æ¢¯)以åæ
绪æ¿å¨åå éã</p><p>é·ï¼å¤ä»£è¡¨å¿èä¾è¡ä¸è¶³ââç»å¿èæä¾è¡æ¶²çå ç¶å¨èåºé®é¢äºã</p><p>严éè¸é·ï¼æ¯å å¿ç
çå¾å
ãè¥æ¯è¿å¨åè¸é·ç¼è§£äºï¼å°±ä¸ç¨æ
å¿ï¼å 为å å¿ç
çè¸é·ä¸å®ä¸ä¼å¨è¿å¨ååè½»ã</p><p>å¦å¤ï¼è·æ¥æ¶åºç°è¸é·è¦å°½å¿«çå»çï¼å«ä»¥ä¸ºä¼æ¯ä¸ä¸å°±è½å¥½ã</p><p>æä¹å?</p><p>åæ´»å¨å¹³æ¿è¿å¨è¯éªï¼å大å»é¢é½æã</p><center><p align="center"><img src="http://img.cnys.com/upload/picture/2017/10-19/cOCh6Z.jpg" alt=""></p></center><p>å¨ç±»ä¼¼è·æ¥æºä¸ç仪å¨ä¸è·æ¥ï¼æ£æµè¿å¨æ¶çå¿çï¼å¹¶è®°å½å¿çµå¾ã</p><p>è·æ¥æ¶é´ä¸è¬ä¸è¶
è¿10åéï¼æä¸äººå¨æçæ¤ï¼å¦æè·çè¿ç¨ä¸ï¼å¿èä¸èæäºï¼å°±ä¼è¢«ååã</p><p>ä¹åï¼å°è·çæ¶é¿ãè·å°å¤å°å¿çä¼æä¸éçææ 综åèµ·æ¥ï¼å¤æå¿èæ¯å¦ç¼ºè¡ã</p>55# </div>56# '''57# })58# article_list.append({59# 'title' : 'é¢é²è
°æ¤é´ççªåºï¼å好è¿5ç¹ï¼',60# 'category' : 'å
»ç常è¯',61# 'read' : 0,62# 'upvote' : 0,63# 'publisher' : 'ä¸åå
»çç½',64# 'publisher_src' : 'http://www.cnys.com/',65# 'href' : 'http://www.cnys.com/xinde/74390.html',66# 'pubdate' : datetime.datetime.now(),67# 'img' : 'http://img.cnys.com/upload/picture/2017/10-19/6FeA8X.jpg',68# 'intro' : '''è
°æ¤é´ççªåºçæ¯æ们ççæ´»ä¸æ¯è¾å¸¸è§çä¸ç§ç¾ç
ï¼å¯¹äºè¿æ ·çä¸ç§ç¾ç
æä»ä¹æ¯è¾å¥½çæ²»çæ¹æ³å¢?69# ''',70# 'content' : '''71# <div class="reads">72# <p>è
°æ¤é´ççªåºçæ¯æ们ççæ´»ä¸æ¯è¾å¸¸è§çä¸ç§ç¾ç
ï¼å¯¹äºè¿æ ·çä¸ç§ç¾ç
æä»ä¹æ¯è¾å¥½çæ²»çæ¹æ³å¢?</p><p><strong>1ã注æä¿æã</strong></p><p>è
°é¨åååä¼è¯±åãå éè
°æ¤é´ççªåºã</p><p><strong>2ãæ£ç¡®ç¨è
°ã</strong></p><p>æ¬æ¬éç©ï¼å
å好åå¤å§¿å¿ï¼ä¸è¦çªç¶ç¨å;æ¬æéç©å°½å¯è½å侧ç¨å;弯è
°æ¡ä¸è¥¿æ¶åå
è¹²ä¸çã</p><p><strong>3ãé¿å
ä¹
åãéå½æ´»å¨ã</strong></p><p>ä¸ç«¯æ£å姿æ¶ï¼è
°æ¤å¤äºå弯çä½ç½®ï¼è
°é¨èèé§å¸¦åå¤å¨ç´§å¼ ç¶æï¼è
°æ¤é´çæ¿åçååå¢å¤§10å!ååå
¬å®¤ç亲å¯ä»¥å¤åæ°´ï¼ç¶åä¼å°¿æ¥ä¸åæï¼ç¶åéè¦åæ¥æ°´ï¼å¼ºè¿«èªå·±æ¶ä¸æ¶å°±å¨èµ·æ¥ã(亲æµææ)</p><center><p align="center"><img src="http://img.cnys.com/upload/picture/2017/10-19/6FeA8X.jpg" alt=""></p></center><p><strong>4ãå°ç©¿é«è·éã</strong></p><p>é«è·é使身ä½çéå¿ç¸å¯¹æé«ï¼äººä½ä¸ºäºç¨³å®éå¿å¹³è¡¡ï¼è
°èé¨èèçå¼ åä¼éæ°è°æ´ï¼ä¸ç´å¤äºç´§ç»·ç¶æï¼å¦æå·²ç»è
°æ¤é´ççªåºï¼åºæ¬éè¦åå«ç©¿é«è·éã</p><p><strong>5ãæå¤ä¼¤åæ¶æ²»çã</strong></p><p>å¤ä¼¤å¦ææ²»çä¸åæ¶å¯è½é ææ
¢æ§æ伤ï¼è¯±åè
°æ¤é´ççªåºãæ们çå°ç»µç¾å°±æ¯å 为é¿æåå¤çå¤å(å¦ç»æ²è¢)é æ轻微æ害ï¼å没æåæ¶çæ²»çï¼æåé æäºæ°¸ä¹
çæ伤ã</p>73# </div>74# '''75# })76# article_list.append({77# 'title' : 'å«è¯´ä½ ä¸ä¿¡ï¼æ°´æè¿çè½ä¼¤çï¼',78# 'category' : 'å
»ç常è¯',79# 'read' : 0,80# 'upvote' : 0,81# 'publisher' : 'ä¸åå
»çç½',82# 'publisher_src' : 'http://www.cnys.com/',83# 'href' : 'http://www.cnys.com/zixun/74382.html',84# 'pubdate' : datetime.datetime.now(),85# 'img' : 'http://img.cnys.com/upload/picture/2017/10-19/9AKi8Q.jpg',86# 'intro' : '''åè¬èæ¯èµ·æ¥ï¼å¹¿å¤§ç人æ°ç¾¤ä¼ä¼¼ä¹æ´å欢水æï¼ä¸»è¦æ¯å 为ç!ç!ç!é®é¢æ¯ï¼æ°´æéçç³ä¼å¼èµ·èçå?è¿ç»å¯¹æ¯ä¸ªé®é¢!87# æ°´ææå¾å¤ç§åæ³ï¼ä¸»è¦ææ°é²æ°´æãæ°´æç½å¤´ãææ±ãå¹²æãæè¯åæé
±çãæ°´æ对ç齿好ä¸å¥½ï¼è¦çæä¹å!88# ''',89# 'content' : '''<div class="reads">90# <p>åè¬èæ¯èµ·æ¥ï¼å¹¿å¤§ç人æ°ç¾¤ä¼ä¼¼ä¹æ´å欢水æï¼ä¸»è¦æ¯å 为ç!ç!ç!é®é¢æ¯ï¼æ°´æéçç³ä¼å¼èµ·èçå?è¿ç»å¯¹æ¯ä¸ªé®é¢!</p><p>æ°´ææå¾å¤ç§åæ³ï¼ä¸»è¦ææ°é²æ°´æãæ°´æç½å¤´ãææ±ãå¹²æãæè¯åæé
±çãæ°´æ对ç齿好ä¸å¥½ï¼è¦çæä¹å!</p><p align="left"></p><h3><strong>æ°é²æ°´æ对ç齿好å?</strong></h3><br><center></center><p>çèµ·æ¥è¿å¯è½æ¯è¿åç´è§ï¼ç¡®å®å«æå¾å¤ç³çæ°´æç¡®å®å¯¹ç齿æ好å¤ãä½æ¯ï¼æ°é²æ°´æåªæä½ä¸ºå¹³è¡¡è³é£çä¸é¨åï¼æ对ç齿æ好å¤ã</p><center><p align="center"><img src="http://img.cnys.com/upload/picture/2017/10-19/9AKi8Q.jpg" alt=""></p></center><p>å¦æä½ æ´å¤©åªåæ°´æï¼å¯¹ç齿就ä¸æ¯é£ä¹å¥½äºãå½ç»å¸¸åæ°´ææ¶ï¼æ¯å¦æ¯å¤©å17次(çæ人è¿ä¹å¹²!)ï¼é£ä¹æ°´æå°±å¯è½å¼èµ·èçãåå é¤äºæ°´æçç³åå¤ï¼è¿æç²å¨ç齿ä¸æªåæ¶æ¸
é¤çæ°´æç¢å±ã</p><p>ç¶èï¼å¦æåªæ¯åé¥ææé¥ååä¸äºæ°é²æ°´æï¼æ²¡æè¯æ®æ¾ç¤ºæ°´æä¼å¼èµ·èçãæ°é²æ°´æå«æå¤ç§ç»´çç´ ï¼å¯¹æ¹åå£è
å¥åº·æ好å¤ã</p><p align="left"></p><h3><strong>æ°´æç½å¤´å¯¹ç齿好å?</strong></h3><br><center></center><p>å¦ä»å¸åºä¸å¤§å¤æ°æ°´æç½å¤´ï¼æ¯æµ¸æ³¡å¨å¯å«ç³çæµç¼©ç³æµä¸çãç±äºè¿äºæ·»å çç³ï¼æ°´æç½å¤´å¯è½å¯¹ç齿é常æ害ã</p><center><p align="center"><img src="http://img.cnys.com/upload/picture/2017/10-19/CNHd0e.jpg" alt=""></p></center><p>å¨åæ°´æç½å¤´ä¹åï¼ççæå表ä¸æ¯å¦å«æç³ã大å¤æ°æ°´æç½å¤´ä¹ä¼å¨æå表ä¸è¯´æå«ææµç¼©ç³æµæè
ç¨éç³æµãè¿å°±è¯´æè¿äºäº§åå«æè¿éçç³!</p>91# </div>92# '''93# })94# article_list.append({95# 'title' : '头æç¼è±å¤±ç å¥å¿é½æ¯è¾æ°ä¸è¶³ï¼å¿«ç¨è¿3个æ¹æ³ç»è¾æææ°ï¼',96# 'category' : 'å
»ç常è¯',97# 'read' : 0,98# 'upvote' : 0,99# 'publisher' : 'ä¸åå
»çç½',100# 'publisher_src' : 'http://www.cnys.com/',101# 'href' : 'http://www.cnys.com/zixun/74365.html',102# 'pubdate' : datetime.datetime.now(),103# 'img' : 'http://img.cnys.com/upload/picture/2017/10-18/SH8mQS.jpg',104# 'intro' : '''头æç¼è±ãè§å模ç³ãè¿æ¯å¤±ç å¥å¿ï¼ä½ 以为æ¯æåäºãåç§äºãè¿æ¯ç表示èªå·±èäº?å
¶å®è¿æä¸ç§å¯è½ï¼é£å°±æ¯è¾æ°ä¸è¶³!105# ''',106# 'content' : '''<div class="reads">107# <p>头æç¼è±ãè§å模ç³ãè¿æ¯å¤±ç å¥å¿ï¼ä½ 以为æ¯æåäºãåç§äºãè¿æ¯ç表示èªå·±èäº?å
¶å®è¿æä¸ç§å¯è½ï¼é£å°±æ¯è¾æ°ä¸è¶³!</p><h3><strong>é£ä¹è¾æ°ä¸è¶³ä¼æä¹æ ·</strong></h3><p><strong>第ä¸ï¼ä¾¿ç§</strong></p><center><p align="center"><img src="http://img.cnys.com/upload/picture/2017/10-18/SH8mQS.jpg" alt=""></p></center><p>为ä»ä¹è¶æ¥è¶å®¹æ便ç§?å 为è人æ´å®¹æè¾æ°ä¸è¶³ï¼ä¸å»è¯´âè¾å¸äºä¾¿âï¼æ以便ç§ãè
¹æ³»ãå°ä¾¿ä¸å©é½ä¸è¾æå
³ã</p><p>é¤äºä¾¿ç§ä¹å¤ï¼è¾æ°ä¸è¶³è¿ä¼è¡¨ç°ä¸ºè
¹æ³»ï¼ä¸è¬åçå¨å¤©äº®ä¹åï¼ä¹ç§°ä¹ä¸ºâäºæ´æ³»âã</p><p><strong>第äºï¼åè²è¿ç¼</strong></p><p>å¨ä¸å»éæä¸ç§è¯´æ³å«åâè¾æ°ä¸è¶³åäºè¿âï¼æè°âäºè¿âæçæ¯åè²è¿ç¼ï¼è¡¨ç°ä¸ºç骨软弱ãåºçè¿ãè¯è¨è¿ãåä¸ç¨³çã</p><p><strong>第ä¸ï¼è³é¸£ãç²¾åä¸æµ</strong></p><center><p align="center"><img src="http://img.cnys.com/upload/picture/2017/10-18/pv4TS9.jpg" alt=""></p></center><p>é常ä¼è¡¨ç°ä¸ºå¬åä¸éãè³é¸£ãå·¥ä½æçä½ã注æäºä¸éä¸ã</p><p><strong>第åï¼è
°é
¸èç</strong></p><p>è¿å ä¹æ¯ææè¾æ°ä¸è¶³äººç¾¤çå
±åçç¶ï¼å°¤å
¶å¨è¿åº¦å³ç´¯ä¹åï¼è
°çãèçé
¸è½¯ä¼è¡¨ç°å¾å¾ææ¾ã</p><p><strong>第äºï¼è±åãè²æãé»ç¼å</strong></p><center><p align="center"><img src="http://img.cnys.com/upload/picture/2017/10-18/zVZkhl.jpg" alt=""></p></center><p>女æ§å
³æ³¨çå¤è²é®é¢ï¼ä¹ä¼åå°è¾æ°ä¸è¶³çå½±åï¼è¡¨ç°ä¸ºç½åå¢å¤ã头åä¸åæå
æ³½ãåºç°é»ç¼åãé»è¤æï¼çè³è¿ä¼ä¼´ææç»ä¸è°ã</p><p><strong>第å
ï¼çå¯æå·ãæµæåå·®</strong></p><p>è¾æ°ä¸è¶³ç女æ§æ´å®¹æçå¯æå·ï¼å³ä½¿ç©¿å¾å¤ï¼å¨å¬å£ä»ç¶ä¼è¡¨ç°ä¸ºæèå°åãæ´å¤åèä¸æ¸©æãä¹å®¹ææåãå³å½ãç¹å»èåäºè§£æ´å¤è¾èå°å¸¸è¯ï¼è¾é³èåä»ä¹å¥½ è¿äºå»ä»·é£ç©è®©ä½ âé³âæ°å足</p><p><strong>第ä¸ï¼åºç°ç¡ç é®é¢</strong></p><center><p align="center"><img src="http://img.cnys.com/upload/picture/2017/10-18/8Fo43X.jpg" alt=""></p></center><p>表ç°ä¸ºæ²¡ç²¾ç¥ï¼è¿ä¼è¡¨ç°ä¸ºé¾ä»¥å
¥ç¡ãç¡ç è´¨éä½ãææéã容æç¦èºçãæ¤å¤ï¼è¾æ°ä¸è¶³è¿ä¼è¡¨ç°ä¸ºæ©è¡°ãå¥å¿ãé£æ¬²ä¸æ¯ãä¹åãä¸èç²å³ä»¥åç齿è¿æ©æ¾å¨ã</p>108# </div>109# '''110# })111# res = articles.insert_many(article_list)112# print res113# print ''114# æå
¥ users éåæ°æ®115# å段说æï¼116# # å¿
å¡«117# 'nickname' : æµç§°118# 'email' : é®ç®±å°å119# 'password' : å¯ç 120# 'sex' : æ§å«ï¼åå¼ï¼0-女ï¼1-ç·ï¼121# 'birthday' : åºçæ¥122# # éå¡«123# 'name' : çå®å§å124# 'phone' : ææºå·125# 'introduction' : 个人ä»ç»126# # ç³»ç»èªå¨çæ127# 'age' : å¹´é¾128# 'usertype' : ç¨æ·ç±»åï¼åå¼ï¼0-游客ï¼1-æ£è
ï¼2-å»çï¼3-管çåï¼129user_list = []130user_list.append({131 # å¿
å¡«132 'nickname' : 'çç
çå°æ',133 'email' : '123456789@qq.com',134 'password' : MD5('123456'),135 'sex' : 1,136 'birthday' : '1994-3-30',137 # éå¡«138 'name' : 'æ¨è±æ',139 'phone' : '12345678901',140 'introduction' : '大家好ï¼ææ¯æ¥çç
ç',141 # ç³»ç»èªå¨çæ142 'age' : 23,143 'usertype' : 1, 144})145user_list.append({146 # å¿
å¡«147 'nickname' : 'èµæ·±å»çåä»',148 'email' : '987654321@qq.com',149 'password' : MD5('123456'),150 'sex' : 1,151 'birthday' : '1974-5-30',152 # éå¡«153 'name' : 'æå',154 'phone' : '12345678902',155 'introduction' : '大家好ï¼æä¼çç
',156 # ç³»ç»èªå¨çæ157 'age' : 43,158 'usertype' : 2, 159})160user_list.append({161 # å¿
å¡«162 'nickname' : 'æ天ä¼æ´å¥½',163 'email' : '987654322@qq.com',164 'password' : MD5('123456'),165 'sex' : 1,166 'birthday' : '1994-1-30',167 # éå¡«168 'name' : 'ç大é¤',169 'phone' : '12345678903',170 'introduction' : '大家好ï¼æå«ç大é¤',171 # ç³»ç»èªå¨çæ172 'age' : 27,173 'usertype' : 1, 174})175res = users.insert_many(user_list)176print res177print ''178"""179# æå
¥ site éåæ°æ®180print 'æå
¥ site éåæ°æ®â¦â¦'181site = []182site.append({183 'title' : 'ç¾åº¦',184 'url' : 'https://www.baidu.com/',185 'desc': 'ç¾åº¦æç´¢å¼æ',186 'create_timestamp' : datetime.datetime.now(),187 'favorite_this_site' : [],188 'tags' : []189})190site.append({191 'title' : 'åå©åå©',192 'url' : 'https://www.bilibili.com/',193 'desc': 'å½å
å¼¹å¹ç½ç« - Bç«',194 'create_timestamp' : datetime.datetime.now(),195 'favorite_this_site' : [],196 'tags' : []197})198site.append({199 'title' : 'Github',200 'url' : 'https://github.com/',201 'desc': 'GitHub æ¯ä¸ä¸ªé¢åå¼æºåç§æ软件项ç®çæ管平å°',202 'create_timestamp' : datetime.datetime.now(),203 'favorite_this_site' : [],204 'tags' : []205})206site.append({207 'title' : 'Readfree',208 'url' : 'http://readfree.me/',209 'desc': 'ä¸ä¸ª kindle çµå书èµæºç«',210 'create_timestamp' : datetime.datetime.now(),211 'favorite_this_site' : [],212 'tags' : []213})214site.append({215 'title' : 'ç¥ä¹',216 'url' : 'https://www.zhihu.com/',217 'desc': 'ç¥ä¹- ä¸ä¸çåäº«ä½ çç¥è¯ãç»éªåè§è§£',218 'create_timestamp' : datetime.datetime.now(),219 'favorite_this_site' : [],220 'tags' : []221})222site.append({223 'title' : 'å客å',224 'url' : 'https://www.cnblogs.com/',225 'desc': 'å客å - 代ç æ¹åä¸ç',226 'create_timestamp' : datetime.datetime.now(),227 'favorite_this_site' : [],228 'tags' : []229})230site.append({231 'title' : 'Google',232 'url' : 'https://www.google.com/',233 'desc': 'è°·ææç´¢ - å
¨çæ大çæç´¢å¼æ',234 'create_timestamp' : datetime.datetime.now(),235 'favorite_this_site' : [],236 'tags' : []237})238site.append({239 'title' : 'ç½æäºé³ä¹',240 'url' : 'http://music.163.com/',241 'desc': 'ç½æäºé³ä¹ - åäº«ä½ çé³ä¹',242 'create_timestamp' : datetime.datetime.now(),243 'favorite_this_site' : [],244 'tags' : []245})246site.append({247 'title' : 'çå - å½ç¶æå¨æ¯æ·¡',248 'url' : 'http://www.yinwang.org/',249 'desc': 'çå çå客',250 'create_timestamp' : datetime.datetime.now(),251 'favorite_this_site' : [],252 'tags' : []253})254site.append({255 'title' : '书èé¨è½',256 'url' : 'https://noveless.com/',257 'desc': '书èé¨è½',258 'create_timestamp' : datetime.datetime.now(),259 'favorite_this_site' : [],260 'tags' : []261})262site.append({263 'title' : 'AcFun',264 'url' : 'http://www.acfun.cn/',265 'desc': 'AcFun - 认çä½ å°±è¾å¦',266 'create_timestamp' : datetime.datetime.now(),267 'favorite_this_site' : [],268 'tags' : []269})270site.append({271 'title' : 'åè¯ - æ¨è±æç个人å客',272 'url' : 'http://www.yangyingming.com/',273 'desc': 'ä¸æ³¨äºc++ãPythonï¼æ¬¢è¿äº¤æµ',274 'create_timestamp' : datetime.datetime.now(),275 'favorite_this_site' : [],276 'tags' : []277})278site.append({279 'title' : 'æ°æµªå¾®å',280 'url' : 'http://weibo.com',281 'desc': 'æ°æµªå¾®å - show åºä½ ççæ´»',282 'create_timestamp' : datetime.datetime.now(),283 'favorite_this_site' : [],284 'tags' : []285})286site.append({287 'title' : 'ä¼é
·',288 'url' : 'http://www.youku.com/',289 'desc': 'è§é¢æå¡å¹³å°,æä¾è§é¢ææ¾,è§é¢åå¸',290 'create_timestamp' : datetime.datetime.now(),291 'favorite_this_site' : [],292 'tags' : []293})294site.append({295 'title' : 'ç±å¥èº',296 'url' : 'http://www.iqiyi.com/',297 'desc': 'å
¨çé¢å
çæä¾æµ·éãä¼è´¨ãé«æ¸
çç½ç»è§é¢æå¡ç大åè§é¢ç½ç«',298 'create_timestamp' : datetime.datetime.now(),299 'favorite_this_site' : [],300 'tags' : []301})302# åå§åæ¯ä¸ªç«ç¹çç¨æ·æ¶èå表303print 'åå§åæ¯ä¸ªç«ç¹çç¨æ·æ¶èå表â¦â¦'304for i in range(len(site)):305 for j in range(10): # æ¯ä¸ªç«æ²¡å¤å°äººæ¶è306 user_no = int(random.random()*len(user))307 print 'ç«ç¹ %s 被ç¨æ· %s æ¶è'%(site[i]['title'],users.find()[user_no]['nickname'].encode('utf8'))308 site[i]['favorite_this_site'].append(users.find()[user_no]['_id'])309res = sites.insert_many(site)310print res311print ''312# æå
¥ tag éåæ°æ®313print 'æå
¥ tag éåæ°æ®â¦â¦'314tag = []315tag.append({316 'title' : 'æç´¢å¼æ',317 'create_timestamp' : datetime.datetime.now()318 })319tag.append({320 'title' : 'å¼¹å¹ç½ç«',321 'create_timestamp' : datetime.datetime.now()322 })323tag.append({324 'title' : 'ACG',325 'create_timestamp' : datetime.datetime.now()326 })327tag.append({328 'title' : 'è§é¢',329 'create_timestamp' : datetime.datetime.now()330 })331tag.append({332 'title' : 'å¼æºç¤¾åº',333 'create_timestamp' : datetime.datetime.now()334 })335tag.append({336 'title' : '社交',337 'create_timestamp' : datetime.datetime.now()338 })339tag.append({340 'title' : 'ç¨åºå',341 'create_timestamp' : datetime.datetime.now()342 })343tag.append({344 'title' : 'èµæº',345 'create_timestamp' : datetime.datetime.now()346 })347tag.append({348 'title' : 'çµå书',349 'create_timestamp' : datetime.datetime.now()350 })351tag.append({352 'title' : 'é®ç社åº',353 'create_timestamp' : datetime.datetime.now()354 })355tag.append({356 'title' : 'å客',357 'create_timestamp' : datetime.datetime.now()358 })359tag.append({360 'title' : 'é³ä¹',361 'create_timestamp' : datetime.datetime.now()362 })363# å mongo æå
¥æ°æ®364res = tags.insert_many(tag)365print res366print ''367print 'åå§åæ¯ä¸ªç½ç«çæ ç¾å表â¦â¦'368def siteAppendTag(site_name,*tag_name_list):369 '''为æ¾å°ç第ä¸ä¸ªå¹é
ç½ç«æ ç¾å表ä¸æ·»å æ ç¾'''370 for tag_name in tag_name_list:371 item = sites.find({'title':site_name})[0]372 if tags.find({'title':tag_name})[0]['_id'] in item['tags']:373 # 该ç½ç«å·²ç»æ·»å è¿è¯¥æ ç¾äº374 continue375 item['tags'].append(tags.find({'title':tag_name})[0]['_id'])376 sites.save(item)377siteAppendTag('ç¾åº¦','æç´¢å¼æ')378siteAppendTag('åå©åå©','å¼¹å¹ç½ç«','ACG','è§é¢')379siteAppendTag('Github','å¼æºç¤¾åº','社交','ç¨åºå')380siteAppendTag('Readfree','èµæº','çµå书')381siteAppendTag('ç¥ä¹','é®ç社åº','社交')382siteAppendTag('å客å','å客')383siteAppendTag('Google','æç´¢å¼æ')384siteAppendTag('ç½æäºé³ä¹','é³ä¹','社交')385siteAppendTag('çå - å½ç¶æå¨æ¯æ·¡','å客')386siteAppendTag('书èé¨è½','èµæº')387siteAppendTag('AcFun','å¼¹å¹ç½ç«','ACG','è§é¢')388siteAppendTag('åè¯ - æ¨è±æç个人å客','å客')389siteAppendTag('æ°æµªå¾®å','社交')390siteAppendTag('ä¼é
·','è§é¢','社交')391siteAppendTag('ç±å¥èº','è§é¢','社交')392# ååºçé¨æ ç¾393for tag in tags.find():394 print 'æ ç¾ %s 被æ è®°è¿ %d 次'%(tag['title'].encode('utf8'),sites.find({'tags':tag['_id']}).count())395# ååºæ¯ä¸ªç«è¢«å¤å°äººæ¶èè¿396for site in sites.find():397 print 'ç½ç« %s 被 %d 人æ¶èè¿'%(site['title'].encode('utf8'),len(site['favorite_this_site']))...
0008_auto_20210603_0950.py
Source:0008_auto_20210603_0950.py
1# Generated by Django 3.1.6 on 2021-06-03 07:502from django.conf import settings3from django.db import migrations, models4import django.db.models.deletion5import django_currentuser.db.models.fields6import django_currentuser.middleware7class Migration(migrations.Migration):8 dependencies = [9 migrations.swappable_dependency(settings.AUTH_USER_MODEL),10 ('train_management', '0007_merge_20210530_1920'),11 ]12 operations = [13 migrations.AddField(14 model_name='availability',15 name='create_timestamp',16 field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='create_timestamp'),17 ),18 migrations.AddField(19 model_name='availability',20 name='create_user',21 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='created_availabilitys', to=settings.AUTH_USER_MODEL),22 ),23 migrations.AddField(24 model_name='availability',25 name='update_timestamp',26 field=models.DateTimeField(auto_now=True, null=True, verbose_name='update_timestamp'),27 ),28 migrations.AddField(29 model_name='availability',30 name='update_user',31 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, on_update=True, related_name='updated_availabilitys', to=settings.AUTH_USER_MODEL),32 ),33 migrations.AddField(34 model_name='copyrecipient',35 name='create_timestamp',36 field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='create_timestamp'),37 ),38 migrations.AddField(39 model_name='copyrecipient',40 name='create_user',41 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='created_copyrecipients', to=settings.AUTH_USER_MODEL),42 ),43 migrations.AddField(44 model_name='copyrecipient',45 name='update_timestamp',46 field=models.DateTimeField(auto_now=True, null=True, verbose_name='update_timestamp'),47 ),48 migrations.AddField(49 model_name='copyrecipient',50 name='update_user',51 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, on_update=True, related_name='updated_copyrecipients', to=settings.AUTH_USER_MODEL),52 ),53 migrations.AddField(54 model_name='dayplanning',55 name='create_timestamp',56 field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='create_timestamp'),57 ),58 migrations.AddField(59 model_name='dayplanning',60 name='create_user',61 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='created_dayplannings', to=settings.AUTH_USER_MODEL),62 ),63 migrations.AddField(64 model_name='dayplanning',65 name='update_timestamp',66 field=models.DateTimeField(auto_now=True, null=True, verbose_name='update_timestamp'),67 ),68 migrations.AddField(69 model_name='dayplanning',70 name='update_user',71 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, on_update=True, related_name='updated_dayplannings', to=settings.AUTH_USER_MODEL),72 ),73 migrations.AddField(74 model_name='dayplanningtext',75 name='create_timestamp',76 field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='create_timestamp'),77 ),78 migrations.AddField(79 model_name='dayplanningtext',80 name='create_user',81 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='created_dayplanningtexts', to=settings.AUTH_USER_MODEL),82 ),83 migrations.AddField(84 model_name='dayplanningtext',85 name='update_timestamp',86 field=models.DateTimeField(auto_now=True, null=True, verbose_name='update_timestamp'),87 ),88 migrations.AddField(89 model_name='dayplanningtext',90 name='update_user',91 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, on_update=True, related_name='updated_dayplanningtexts', to=settings.AUTH_USER_MODEL),92 ),93 migrations.AddField(94 model_name='dvzofunction',95 name='create_timestamp',96 field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='create_timestamp'),97 ),98 migrations.AddField(99 model_name='dvzofunction',100 name='create_user',101 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='created_dvzofunctions', to=settings.AUTH_USER_MODEL),102 ),103 migrations.AddField(104 model_name='dvzofunction',105 name='update_timestamp',106 field=models.DateTimeField(auto_now=True, null=True, verbose_name='update_timestamp'),107 ),108 migrations.AddField(109 model_name='dvzofunction',110 name='update_user',111 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, on_update=True, related_name='updated_dvzofunctions', to=settings.AUTH_USER_MODEL),112 ),113 migrations.AddField(114 model_name='mileage',115 name='create_timestamp',116 field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='create_timestamp'),117 ),118 migrations.AddField(119 model_name='mileage',120 name='create_user',121 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='created_mileages', to=settings.AUTH_USER_MODEL),122 ),123 migrations.AddField(124 model_name='mileage',125 name='update_timestamp',126 field=models.DateTimeField(auto_now=True, null=True, verbose_name='update_timestamp'),127 ),128 migrations.AddField(129 model_name='mileage',130 name='update_user',131 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, on_update=True, related_name='updated_mileages', to=settings.AUTH_USER_MODEL),132 ),133 migrations.AddField(134 model_name='personnel',135 name='create_timestamp',136 field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='create_timestamp'),137 ),138 migrations.AddField(139 model_name='personnel',140 name='create_user',141 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='created_personnels', to=settings.AUTH_USER_MODEL),142 ),143 migrations.AddField(144 model_name='personnel',145 name='update_timestamp',146 field=models.DateTimeField(auto_now=True, null=True, verbose_name='update_timestamp'),147 ),148 migrations.AddField(149 model_name='personnel',150 name='update_user',151 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, on_update=True, related_name='updated_personnels', to=settings.AUTH_USER_MODEL),152 ),153 migrations.AddField(154 model_name='phonenumber',155 name='create_timestamp',156 field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='create_timestamp'),157 ),158 migrations.AddField(159 model_name='phonenumber',160 name='create_user',161 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='created_phonenumbers', to=settings.AUTH_USER_MODEL),162 ),163 migrations.AddField(164 model_name='phonenumber',165 name='update_timestamp',166 field=models.DateTimeField(auto_now=True, null=True, verbose_name='update_timestamp'),167 ),168 migrations.AddField(169 model_name='phonenumber',170 name='update_user',171 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, on_update=True, related_name='updated_phonenumbers', to=settings.AUTH_USER_MODEL),172 ),173 migrations.AddField(174 model_name='reservation',175 name='create_timestamp',176 field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='create_timestamp'),177 ),178 migrations.AddField(179 model_name='reservation',180 name='create_user',181 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='created_reservations', to=settings.AUTH_USER_MODEL),182 ),183 migrations.AddField(184 model_name='reservation',185 name='update_timestamp',186 field=models.DateTimeField(auto_now=True, null=True, verbose_name='update_timestamp'),187 ),188 migrations.AddField(189 model_name='reservation',190 name='update_user',191 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, on_update=True, related_name='updated_reservations', to=settings.AUTH_USER_MODEL),192 ),193 migrations.AddField(194 model_name='route',195 name='create_timestamp',196 field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='create_timestamp'),197 ),198 migrations.AddField(199 model_name='route',200 name='create_user',201 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='created_routes', to=settings.AUTH_USER_MODEL),202 ),203 migrations.AddField(204 model_name='route',205 name='update_timestamp',206 field=models.DateTimeField(auto_now=True, null=True, verbose_name='update_timestamp'),207 ),208 migrations.AddField(209 model_name='route',210 name='update_user',211 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, on_update=True, related_name='updated_routes', to=settings.AUTH_USER_MODEL),212 ),213 migrations.AddField(214 model_name='station',215 name='create_timestamp',216 field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='create_timestamp'),217 ),218 migrations.AddField(219 model_name='station',220 name='create_user',221 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='created_stations', to=settings.AUTH_USER_MODEL),222 ),223 migrations.AddField(224 model_name='station',225 name='update_timestamp',226 field=models.DateTimeField(auto_now=True, null=True, verbose_name='update_timestamp'),227 ),228 migrations.AddField(229 model_name='station',230 name='update_user',231 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, on_update=True, related_name='updated_stations', to=settings.AUTH_USER_MODEL),232 ),233 migrations.AddField(234 model_name='train',235 name='create_timestamp',236 field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='create_timestamp'),237 ),238 migrations.AddField(239 model_name='train',240 name='create_user',241 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='created_trains', to=settings.AUTH_USER_MODEL),242 ),243 migrations.AddField(244 model_name='train',245 name='update_timestamp',246 field=models.DateTimeField(auto_now=True, null=True, verbose_name='update_timestamp'),247 ),248 migrations.AddField(249 model_name='train',250 name='update_user',251 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, on_update=True, related_name='updated_trains', to=settings.AUTH_USER_MODEL),252 ),253 migrations.AddField(254 model_name='trainconfiguration',255 name='create_timestamp',256 field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='create_timestamp'),257 ),258 migrations.AddField(259 model_name='trainconfiguration',260 name='create_user',261 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='created_trainconfigurations', to=settings.AUTH_USER_MODEL),262 ),263 migrations.AddField(264 model_name='trainconfiguration',265 name='update_timestamp',266 field=models.DateTimeField(auto_now=True, null=True, verbose_name='update_timestamp'),267 ),268 migrations.AddField(269 model_name='trainconfiguration',270 name='update_user',271 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, on_update=True, related_name='updated_trainconfigurations', to=settings.AUTH_USER_MODEL),272 ),273 migrations.AddField(274 model_name='traintimetable',275 name='create_timestamp',276 field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='create_timestamp'),277 ),278 migrations.AddField(279 model_name='traintimetable',280 name='create_user',281 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='created_traintimetables', to=settings.AUTH_USER_MODEL),282 ),283 migrations.AddField(284 model_name='traintimetable',285 name='update_timestamp',286 field=models.DateTimeField(auto_now=True, null=True, verbose_name='update_timestamp'),287 ),288 migrations.AddField(289 model_name='traintimetable',290 name='update_user',291 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, on_update=True, related_name='updated_traintimetables', to=settings.AUTH_USER_MODEL),292 ),293 migrations.AddField(294 model_name='traintimetabletemplate',295 name='create_timestamp',296 field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='create_timestamp'),297 ),298 migrations.AddField(299 model_name='traintimetabletemplate',300 name='create_user',301 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='created_traintimetabletemplates', to=settings.AUTH_USER_MODEL),302 ),303 migrations.AddField(304 model_name='traintimetabletemplate',305 name='update_timestamp',306 field=models.DateTimeField(auto_now=True, null=True, verbose_name='update_timestamp'),307 ),308 migrations.AddField(309 model_name='traintimetabletemplate',310 name='update_user',311 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, on_update=True, related_name='updated_traintimetabletemplates', to=settings.AUTH_USER_MODEL),312 ),313 migrations.AddField(314 model_name='vehicle',315 name='create_timestamp',316 field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='create_timestamp'),317 ),318 migrations.AddField(319 model_name='vehicle',320 name='create_user',321 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='created_vehicles', to=settings.AUTH_USER_MODEL),322 ),323 migrations.AddField(324 model_name='vehicle',325 name='update_timestamp',326 field=models.DateTimeField(auto_now=True, null=True, verbose_name='update_timestamp'),327 ),328 migrations.AddField(329 model_name='vehicle',330 name='update_user',331 field=django_currentuser.db.models.fields.CurrentUserField(default=django_currentuser.middleware.get_current_authenticated_user, null=True, on_delete=django.db.models.deletion.CASCADE, on_update=True, related_name='updated_vehicles', to=settings.AUTH_USER_MODEL),332 ),...
report.py
Source:report.py
...26 print ("Successfully created the directory %s" % self.file_path)27 def begin(self):28 temp = ""29 self.text_to_print = ""30 #st = self.create_timestamp()31 st = ""32 temp += self.append(str(st)+"Date"+","+"Current"+","+"Voltage"+","+"Temperature"+","+"Amper/Hour"+","+"Amper Acu."+","+"Step"+","+"Step State"+","+"Time"+","+"Current Time"+","+"Total Time"+","+"Status\r\n")33 #temp += self.append(str(st)+" **************************************************************************\r\n")34 #st = self.create_timestamp()35 #temp += self.append(str(st)+" ****************************** REPORT BEGIN ******************************\r\n")36 #st = self.create_timestamp()37 ltext = 7438 lsn = len(self.address_number)+639 spaces = (ltext-lsn)/240 remBanner = (ltext-lsn)%241 strBanner = ""42 strFillBanner = ""43 #for n in range(0,int(spaces)):44 # strBanner+="*"45 #for n in range(0,int(remBanner)):46 # strFillBanner+="*"47 #temp += self.append(str(st)+" "+strBanner+" SN: ")48 #temp += self.append(self.address_number + " ")49 #temp += self.append(strBanner+strFillBanner+"\r\n")50 #st = self.create_timestamp()51 #temp += self.append(str(st)+" **************************************************************************\r\n")52 self.text_to_print += temp53 return temp54 55 def end(self):56 temp = ""57 st = self.create_timestamp()58 temp += self.append(str(st)+" **************************************************************************\r\n")59 st = self.create_timestamp()60 temp += self.append(str(st)+" ******************************* REPORT END *******************************\r\n")61 st = self.create_timestamp()62 temp += self.append(str(st)+" **************************************************************************\r\n\r\n")63 self.text_to_print += temp64 return temp65 66 def append(self, text):67 if self.address_number == None:68 raise Exception("IndividualReportError", "No Serial Number as FileName was Assigned!")69 if os.path.isfile(self.file_name): # if file exists70 file = open(self.file_name, "a+") # we append71 file.write(text)72 file.close()73 else:74 file = open(self.file_name, "w+") # we create a new file75 file.write(text)76 file.close()77 return text78 79 def appendWithTimeStamp(self, text):80 if self.address_number == None:81 raise Exception("IndividualReportError", "No Serial Number as FileName was Assigned!")82 st = self.create_timestamp()83 temp = str(st)+" "+ text + "\r\n"84 self.append(temp)85 self.text_to_print += temp86 return temp87 88 def appendWithTimeStampUsingFile(self, text, file):89 if not StringUtils.isNoneOrEmpty(file):90 self.address_number = file91 self.file_name = self.file_path + self.address_number + '.xls' #'.txt'92 if not os.path.exists(self.file_name):93 self.begin()94 st = self.create_timestamp()95 temp = str(st)+" "+ text + "\r\n"96 self.append(temp)97 self.text_to_print += temp98 return temp99 def create_timestamp(self):100 now = datetime.now()101 st = now.strftime('%Y-%m-%d %H:%M:%S') #+ ('.%04d' % (now.microsecond / 100))102 #print(st)103 return st104 def print(self):105 return self.text_to_print106class MainReport:107 home = str(Path.home())108 #if appsettings.useDesktopToSaveReports:109 file_path = home +'/TestLogs/'110 #else:111 #file_path = os.getcwd() + '/TestLogs/'112 file_name = None113 address_number = None114 date_created = None115 date_modified = None116 text_to_print = ""117 def __init__(self):118 try:119 os.makedirs(self.file_path)120 except OSError:121 print ("Creation of the directory %s failed" % self.file_path)122 else:123 print ("Successfully created the directory %s" % self.file_path)124 self.file_name = self.file_path+'mainlog.txt'125 self.text_to_print = ""126 def begin(self):127 temp = ""128 self.text_to_print = ""129 st = self.create_timestamp()130 temp += self.append(str(st)+" **************************************************************************\r\n")131 st = self.create_timestamp()132 temp += self.append(str(st)+" **************************** MAIN REPORT BEGIN ***************************\r\n")133 st = self.create_timestamp()134 temp += self.append(str(st)+" **************************************************************************\r\n")135 self.text_to_print += temp136 return temp137 def end(self):138 temp = ""139 st = self.create_timestamp()140 temp += self.append(str(st)+" **************************************************************************\r\n")141 st = self.create_timestamp()142 temp += self.append(str(st)+" ***************************** MAIN REPORT END ****************************\r\n")143 st = self.create_timestamp()144 temp += self.append(str(st)+" **************************************************************************\r\n\r\n")145 self.text_to_print += temp146 return temp147 def append(self, text):148 if os.path.isfile(self.file_name): # if file exists149 file = open(self.file_name, "a+") # we append150 file.write(text)151 file.close()152 else:153 file = open(self.file_name, "w+") # we create a new file154 file.write(text)155 file.close()156 return text157 def appendWithTimeStamp(self, text):158 st = self.create_timestamp()159 temp = str(st)+" "+text + "\r\n"160 self.append(temp)161 self.text_to_print += temp162 return temp163 def create_timestamp(self):164 now = datetime.now()165 st = now.strftime('%Y-%m-%d %H:%M:%S') + ('.%04d' % (now.microsecond / 100))166 #print(st)167 return st168 def print(self):169 return self.text_to_print170if __name__ == '__main__':171 print("report demo")172 #mreport = MainReport()173 #mreport.begin()174 #mreport.end()175 #ireport = [None, None, None]176 177 ireport = IndividualReport()...
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!!