How to use created method in molecule

Best Python code snippet using molecule_python

party_models.py

Source:party_models.py Github

copy

Full Screen

1from datetime import datetime2from flask import jsonify3""" Dictionary containing parties """4political_parties = {}5class PoliticalParties:6 @staticmethod7 def create_party(party_data):8 msgResponse = ''9 if len(party_data) < 3:10 """ check if submitted data is complete, i.e has all parameters required"""11 responseCreated = {"status": 406,12 "message": "The information provided is incomplete please update to proceed"13 }14 msgResponse = jsonify(responseCreated), 40615 elif any(political_parties[i]["name"] == party_data["name"] for i in political_parties.keys()) and (party_data["hqAddress"].strip() != "" and party_data["logourl"].strip() != ""):16 """ check if party has already been created and return already created message if true """17 responseCreated = {"status": 400,18 "message": "The party already exists"19 }20 msgResponse = jsonify(responseCreated), 40021 elif str(party_data["name"]) == "":22 """ check if party name enetered is valid """23 responseCreated = {"status": 406,24 "message": "Please enter a valid name!"25 }26 msgResponse = jsonify(responseCreated), 40627 elif str(party_data["hqAddress"]) == "":28 """ check if party address enetered is valid """29 responseCreated = {"status": 406,30 "message": "Please enter a valid Address!"31 }32 msgResponse = jsonify(responseCreated), 40633 elif str(party_data["logourl"]) == "":34 """ check if party logourl enetered is valid """35 responseCreated = {"status": 406,36 "message": "Please enter a valid url!"37 }38 msgResponse = jsonify(responseCreated), 40639 else:40 """ Add party to list if all conditions are met """41 id_count = len(political_parties)42 id_count = id_count + 143 party_data["datecreated"] = datetime.utcnow()44 party_data['id'] = id_count45 political_parties[id_count] = party_data46 responseCreated = {"status": 201,47 "data": party_data48 }49 msgResponse = jsonify(responseCreated), 20150 return msgResponse51 @staticmethod52 def get_all_parties():53 """ Fetch all political parties """54 msgResponse = ''55 if len(political_parties) > 0:56 responseCreated = {"status": 200,57 "data": political_parties58 }59 msgResponse = jsonify(responseCreated), 20060 else:61 responseCreated = {"status": 200,62 "message": "No party created"63 }64 msgResponse = jsonify(responseCreated), 20065 return msgResponse66 @staticmethod67 def get_specific_party(partyid):68 msgResponse = ""69 if len(political_parties) != 0:70 if partyid in political_parties:71 party_data = political_parties[partyid]72 responseCreated = {"status": 200,73 "data": [party_data]74 }75 msgResponse = jsonify(responseCreated), 20076 else:77 responseCreated = {"status": 404,78 "message": "Party not found."79 }80 msgResponse = jsonify(responseCreated), 40481 else:82 responseCreated = {"status": 404,83 "message": "No parties found"84 }85 msgResponse = jsonify(responseCreated), 40486 return msgResponse87 @staticmethod88 def edit_party_name(party_id, party_name):89 """ Edits name of a specific party """90 msgResponse = ""91 if len(political_parties) != 0:92 if party_id in political_parties:93 political_parties[party_id]["id"] = party_id94 political_parties[party_id]["name"] = party_name["name"]95 party_data = dict(id=party_id, name=party_name["name"])96 responseCreated = {"status": 200,97 "data": [party_data]98 }99 msgResponse = jsonify(responseCreated), 200100 else:101 responseCreated = {"status": 404,102 "message": "Party not found"103 }104 msgResponse = jsonify(responseCreated), 404105 else:106 responseCreated = {"status": 404,107 "message": "No parties found"108 }109 msgResponse = jsonify(responseCreated), 404110 return msgResponse111 @staticmethod112 def delete_party(partyid):113 """ Deletes specific party """114 msgResponse = ""115 if len(political_parties) != 0:116 if partyid in political_parties:117 del political_parties[partyid]118 responseCreated = {"status": 200,119 "data": political_parties120 }121 msgResponse = jsonify(responseCreated), 200122 else:123 responseCreated = {"status": 404,124 "message": "Party not found"125 }126 msgResponse = jsonify(responseCreated), 404127 else:128 responseCreated = {"status": 404,129 "message": "No parties found"130 }131 msgResponse = jsonify(responseCreated), 404...

Full Screen

Full Screen

util.py

Source:util.py Github

copy

Full Screen

1import sys2from datetime import datetime, timedelta3from weibo.utils.region import region_dict4def convert_weibo_type(weibo_type):5 """将微博类型转换成字符串"""6 if weibo_type == 0:7 return '&typeall=1'8 elif weibo_type == 1:9 return '&scope=ori'10 elif weibo_type == 2:11 return '&xsort=hot'12 elif weibo_type == 3:13 return '&atten=1'14 elif weibo_type == 4:15 return '&vip=1'16 elif weibo_type == 5:17 return '&category=4'18 elif weibo_type == 6:19 return '&viewpoint=1'20 return '&scope=ori'21def convert_contain_type(contain_type):22 """将包含类型转换成字符串"""23 if contain_type == 0:24 return '&suball=1'25 elif contain_type == 1:26 return '&haspic=1'27 elif contain_type == 2:28 return '&hasvideo=1'29 elif contain_type == 3:30 return '&hasmusic=1'31 elif contain_type == 4:32 return '&haslink=1'33 return '&suball=1'34def get_keyword_list(file_name):35 """获取文件中的关键词列表"""36 with open(file_name, 'rb') as f:37 try:38 lines = f.read().splitlines()39 lines = [line.decode('utf-8-sig') for line in lines]40 except UnicodeDecodeError:41 print(u'%s文件应为utf-8编码,请先将文件编码转为utf-8再运行程序', file_name)42 sys.exit()43 keyword_list = []44 for line in lines:45 if line:46 keyword_list.append(line)47 return keyword_list48def get_regions(region):49 """根据区域筛选条件返回符合要求的region"""50 new_region = {}51 if region:52 for key in region:53 if region_dict.get(key):54 new_region[key] = region_dict[key]55 if not new_region:56 new_region = region_dict57 return new_region58def standardize_date(created_at):59 """标准化微博发布时间"""60 if "刚刚" in created_at:61 created_at = datetime.now().strftime("%Y-%m-%d %H:%M")62 elif "秒" in created_at:63 second = created_at[:created_at.find(u"秒")]64 second = timedelta(seconds=int(second))65 created_at = (datetime.now() - second).strftime("%Y-%m-%d %H:%M")66 elif "分钟" in created_at:67 minute = created_at[:created_at.find(u"分钟")]68 minute = timedelta(minutes=int(minute))69 created_at = (datetime.now() - minute).strftime("%Y-%m-%d %H:%M")70 elif "小时" in created_at:71 hour = created_at[:created_at.find(u"小时")]72 hour = timedelta(hours=int(hour))73 created_at = (datetime.now() - hour).strftime("%Y-%m-%d %H:%M")74 elif "今天" in created_at:75 today = datetime.now().strftime('%Y-%m-%d')76 created_at = today + ' ' + created_at[2:]77 elif '年' not in created_at:78 year = datetime.now().strftime("%Y")79 month = created_at[:2]80 day = created_at[3:5]81 time = created_at[6:]82 created_at = year + '-' + month + '-' + day + ' ' + time83 else:84 year = created_at[:4]85 month = created_at[5:7]86 day = created_at[8:10]87 time = created_at[11:]88 created_at = year + '-' + month + '-' + day + ' ' + time89 return created_at90def str_to_time(text):91 """将字符串转换成时间类型"""92 result = datetime.strptime(text, '%Y-%m-%d')...

Full Screen

Full Screen

Project Metrics Processing Script.py

Source:Project Metrics Processing Script.py Github

copy

Full Screen

1#!/usr/bin/env python2# coding: utf-83# This script creates a table from using data from JIRA and calculates how many User Stories and Bugs were Created and Resolved per day per project.4import pandas as pd5df = pd.read_csv(r'C:\Users\ishan.khoche\Documents\Project Metrics\Projec Metrics Dashboard Data_23Oct- Copy.csv') #Load File to be analyzed6fixedversion = df.loc[df['Fixed Version'] == 'ZS Web 2.0Mallorca'] # Enter Fixed Version7bug = fixedversion.loc[fixedversion['Issue Type'] == 'Bug'] 8bug['created date'] = pd.to_datetime(bug['Created']).dt.date 9bug['Created/Resolved'] = 'Created' #add column to mark that these are created bugs10createdBugs = bug.groupby(['created date', 'Fixed Version','Created/Resolved']).size() #Count of Created/Day11bug['resolved date'] = pd.to_datetime(bug['Resolved']).dt.date 12bug['Created/Resolved'] = 'Resolved' #add column to mark that these are resolved bugs13resolvedBugs = bug.groupby(['resolved date', 'Fixed Version','Created/Resolved']).size() #Count of Resolved/Day14#Change name of file below:15createdBugs.append(resolvedBugs).to_csv('ZS Web 2.0Mallorca_bugs.csv') # Create file with bugs created/resolved counts16userstories = fixedversion.loc[fixedversion['Issue Type'] == 'Story'] 17userstories['created date'] = pd.to_datetime(userstories['Created']).dt.date 18userstories['Created/Resolved'] = 'Created' #add column to mark that these are created bugs19createduserstories = userstories.groupby(['created date', 'Fixed Version','Created/Resolved']).size() #Count of Created/Day20userstories['resolved date'] = pd.to_datetime(userstories['Resolved']).dt.date 21userstories['Created/Resolved'] = 'Resolved' #add column to mark that these are resolved bugs22resolveduserstories = userstories.groupby(['resolved date', 'Fixed Version','Created/Resolved']).size() #Count of Resolved/Day23#Change name of file below:...

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 molecule 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