Best Python code snippet using lemoncheesecake
mapping.py
Source:mapping.py
...18 cfg['BaseAttributes']['Manufacturer'] = wsi.get('openslide.vendor')19 if not cfg.get('BaseAttributes').get('SeriesDescription'):20 cfg['BaseAttributes']['SeriesDescription'] = str(wsi.get('aperio.ImageID'))21 if not cfg.get('BaseAttributes').get('ContentTime'):22 _, cfg = utils.make_time('ContentTime', wsi.get('aperio.Time'), cfg,23 dict_element='SharedFunctionalGroupsSequence')24 if not cfg.get('BaseAttributes').get('SeriesTime'):25 _, cfg = utils.make_time('SeriesTime', wsi.get('aperio.Time'), cfg,26 dict_element='SharedFunctionalGroupsSequence')27 if not cfg.get('BaseAttributes').get('StudyTime'):28 _, cfg = utils.make_time('StudyTime', wsi.get('aperio.Time'), cfg,29 dict_element='SharedFunctionalGroupsSequence')30 pv = wsi.get('openslide.mpp-x'), wsi.get('openslide.mpp-y')31 cfg['OnTheFly']['PixelSpacing'] = [float(x) for x in pv]32 return cfg33def map_other_features(cfg, wsi):34 """35 Update attributes by mapping from vendor specific attributes to DICOM attributes36 :param cfg:37 :param wsi:38 :return:39 """40 fields = wsi.get_fields()41 cfg['OnTheFly'] = dict()42 logger.debug(f'Looking through fields:{fields}')43 if not cfg.get('BaseAttributes').get('Manufacturer'):44 cfg['BaseAttributes']['Manufacturer'] = wsi.get('openslide.vendor')45 if not cfg.get('BaseAttributes').get('SeriesDescription'):46 try:47 target = [field for field in fields if "ImageID" in field][0]48 cfg['BaseAttributes']['SeriesDescription'] = str(wsi.get(target))49 except:50 logging.warning(f'SeriesDescription not provided')51 cfg['BaseAttributes']['SeriesDescription'] = 'No description provided'52 if not cfg.get('BaseAttributes').get('ContentTime'):53 _, cfg = utils.make_time('ContentTime', wsi.get('aperio.Time'), cfg,54 dict_element='SharedFunctionalGroupsSequence')55 try:56 target = [field for field in fields if "Time" in field][0]57 logger.debug(f'Found target: {target}')58 if not cfg.get('BaseAttributes').get('SeriesTime'):59 _, cfg = utils.make_time('SeriesTime', wsi.get(target), cfg,60 dict_element='SharedFunctionalGroupsSequence')61 if not cfg.get('BaseAttributes').get('StudyTime'):62 _, cfg = utils.make_time('StudyTime', wsi.get(target), cfg,63 dict_element='SharedFunctionalGroupsSequence')64 if not cfg.get('BaseAttributes').get('ContentTime'):65 _, cfg = utils.make_time('ContentTime', wsi.get(target), cfg,66 dict_element='SharedFunctionalGroupsSequence')67 except IndexError:68 now = datetime.now().strftime("%H%M%S.%f")69 logging.warning(f'Unable to find StudyTime/SeriesTime. Using datenow({now}) instead')70 if not cfg.get('BaseAttributes').get('StudyTime'):71 _, cfg = utils.make_time('StudyTime', now, cfg,72 dict_element='SharedFunctionalGroupsSequence')73 if not cfg.get('BaseAttributes').get('SeriesTime'):74 _, cfg = utils.make_time('SeriesTime', now, cfg,75 dict_element='SharedFunctionalGroupsSequence')76 if not cfg.get('BaseAttributes').get('ContentTime'):77 _, cfg = utils.make_time('ContentTime', now, cfg,78 dict_element='SharedFunctionalGroupsSequence')79 try:80 pv = wsi.get('openslide.mpp-x'), wsi.get('openslide.mpp-y')81 except pyvips.error.Error:82 try:83 logger.warning('openslide.mpp-? not found. trying config file')84 pv = cfg.get('BaseAttributes').get('PixelSpacing')85 logger.warning(f'PV: {pv}')86 except:87 logger.error('openslide.mpp-? not found in config file or image file')88 raise AttributeError("openslide.mpp-? not found. You need to specify these values in your"89 " base.yaml: BaseAttributes.PixelSpacing: x,y")90 cfg['OnTheFly']['PixelSpacing'] = [float(x) for x in pv]91 return cfg
board.py
Source:board.py
...68 rq = RawQuery(cls, "select * from words where words like ?", words)69 return rq.execute()7071 @classmethod72 def get_by_make_time(cls, make_time):73 return cls.get_one(cls.make_time == make_time)7475 @classmethod76 def count(cls, username):77 return cls.select().where(cls.username == username).count()7879 @classmethod80 def num_lim(cls, username):81 if cls.count(username) >= 100:82 return True8384 @classmethod85 def get_one(cls, *query, **kwargs):86 try:
...
main.py
Source:main.py
...3import os4import vk_api5from post import make_posts6from config import *7def make_time():8 return datetime.datetime.now().strftime("%H:%M:%S")9def two_factor():10 code = input('Enter Two-factor Auth code: ')11 remember_device = True12 return code, remember_device13def main():14 vk_session = vk_api.VkApi(LOGIN, PASSWORD,15 auth_handler=two_factor,16 app_id=APP_ID,17 scope=PERMISSIONS,18 config_filename='vk_config.v2.json')19 vk_session.auth()20 posts_path = os.getcwd() + '/posts/'21 print('Posts:')22 posts = make_posts(posts_path)23 print('=' * 40)24 for post in posts: 25 td = ( post.time - datetime.datetime.now() ).total_seconds()26 if td < 0:27 print(post.time, '- wrong post time')28 print('-' * 40)29 continue30 else:31 while True:32 td = ( post.time - datetime.datetime.now() ).total_seconds()33 if td < 60:34 try:35 print('[{}] Uploading files to server vk...'.format(make_time()))36 post.upload_content(vk_session, USER_ID, GROUP_ID)37 38 print('[{}] Posting...'.format(make_time()))39 post.post(vk_session, GROUP_ID)40 41 print('[{}] Success!'.format(make_time()))42 except Exception as err:43 print('[{}] {} - Error {}'.format(make_time(), post.time, err))44 break45 else:46 print('[{}] sleep {} min'.format(make_time(), round((td - 40)/60, 1)))47 sleep(td - 40)48 print('-' * 40)49if __name__ == '__main__':...
mysql-query-xy.py
Source:mysql-query-xy.py
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3# å 载模å4import sys5import MySQLdb6# 设置é»è®¤ç¼ç 为UTF-8ï¼å¦åä»æ°æ®åº7# 读åºçUTF-8æ°æ®æ æ³æ£å¸¸æ¾ç¤º8reload(sys)9sys.setdefaultencoding('utf-8')10# è¿æ¥æ°æ®åº11conn = MySQLdb.Connection(host="192.168.1.225", user="selecter", passwd="fxdata_Select-2016", charset="UTF8")12conn.select_db('cds_v2')13# å建æéï¼å¹¶è®¾ç½®æ°æ®çè¿å模å¼ä¸ºåå
¸14cursor = conn.cursor(MySQLdb.cursors.DictCursor)15# æ§è¡SQL16for i in range(25,26):17 m=str(i)18 n=str(i+1)19 s=m.zfill(2)20 t=n.zfill(2)21 sql=("SELECT * FROM (SELECT `make_time` - `make_time` %% (500) AS `newtime`, sum(per1sum) / 300 * 8 AS `per5avg` FROM (SELECT make_time,sum(proxy_cache_size) AS proxy_cache_sizes,sum(service_size) AS service_sizes,sum(service_size)-sum(proxy_cache_size) as per1sum FROM `cds_v2`.`operation_stat` WHERE make_time >= '2016-12-%s 00:00:00' AND make_time < '2016-12-%s 00:00:00' AND sn like '%%A%%' AND sn not like '%%0530000196' AND sn not like '%%0530000152' AND category = 152 group by make_time) AS `a` GROUP BY `make_time` - `make_time` %% (500) ) AS `b` ORDER BY per5avg limit 1;")%(s,t)22 cursor.execute(sql)23 result=cursor.fetchall()24 print result25# å
³éæé26cursor.close()27# å
³éæ°æ®åºè¿æ¥...
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!!