How to use create_pie_chart method in SeleniumBase

Best Python code snippet using SeleniumBase

main.py

Source:main.py Github

copy

Full Screen

...138 details = req_body['details']139 success = True140 response = ''141 if 'create_pie_chart' in details and details['create_pie_chart'] and details['pie_data']:142 pie_response = create_pie_chart(details['pie_data'], BASE_PRESENTATION)143 success = success and pie_response[0]144 response = "{pr}".format(response=response, pr=pie_response[1])145 if 'create_bar_chart' in details and details['create_bar_chart'] and details['bar_data']:146 bar_response = create_bar_chart(details['bar_data'], BASE_PRESENTATION)147 success = success and bar_response[0]148 response = "{response}. {br}".format(response=response, br=bar_response[1])149 if 'create_line_chart' in details and details['create_line_chart'] and details['line_data']:150 line_response = create_line_chart(details['line_data'], BASE_PRESENTATION)151 success = success and line_response[0]152 response = "{response}. {lr}".format(response=response, lr=line_response[1])153 if success:154 return True, response155 else:156 return False, response157@app.route("/", methods=['POST'])158def ppt_request_handle():159 print("in ppt_request_handle")160 req = request.json161 print(req)162 with open("req_sample.json", "w") as outfile:163 json.dump(req, outfile)164 if req["req"] == "create_ppt" and req["source"].lower() == "wikipedia":165 result = create_ppt(req["title"])166 if result[0]:167 response = {168 "message": "Request successful",169 "title": result[1]170 }171 return jsonify(response), 200172 elif req["req"] == "create_ppt_count" and req["source"].lower() == "wikipedia":173 result = create_ppt_with_count(req["title"], req["count"])174 if result[0]:175 response = {176 "message": "Request successful",177 "title": result[1],178 "count": result[2],179 }180 return jsonify(response), 200181 elif req["req"] == "create_ppt_count" and req["source"].lower() == "nytimes":182 result = create_ppt_ny(req["title"], req["count"])183 if result[0]:184 response = {185 "message": "Request successful",186 "title": result[1],187 "count": result[2],188 }189 return jsonify(response), 200190 elif req["req"] == "create_team_slide":191 result = create_team_slide(req["people"])192 response = {193 "message": result[1]194 }195 if result[0]:196 return jsonify(response), 200197 else:198 return jsonify(response), 400199 elif req["req"] == "create_pie_chart":200 result = create_pie_chart(req, BASE_PRESENTATION)201 response = {202 "message": result[1]203 }204 if result[0]:205 return jsonify(response), 200206 else:207 return jsonify(response), 400208 elif req["req"] == "create_bar_chart":209 result = create_bar_chart(req, BASE_PRESENTATION)210 response = {211 "message": result[1]212 }213 if result[0]:214 return jsonify(response), 200215 else:216 return jsonify(response), 400217 elif req["req"] == "create_line_chart":218 result = create_line_chart(req, BASE_PRESENTATION)219 response = {220 "message": result[1]221 }222 if result[0]:223 return jsonify(response), 200224 else:225 return jsonify(response), 400226 elif req["req"] == "create_chart" or req["req"] == "create_charts":227 result = create_charts(req)228 response = {229 "message": result[1]230 }231 if result[0]:232 return jsonify(response), 200233 else:234 return jsonify(response), 400235 elif req["req"] == "create_org_chart":236 result = True, 'Got the request'237 response = {238 "message": result[1]239 }240 if result[0]:241 return jsonify(response), 200242 else:243 return jsonify(response), 400244 return f"Cannot process request", 400245# 'Main' function to run246if __name__ == '__main__':247 # app.run(debug=True) # run server in debug mode248 os.chdir("/Users/vishal/Documents/Auxi/PIII-Prototype/PIII-Prototype-First")249 with open('./1.json') as json_file:250 data = json.load(json_file)251 print(data)252 create_ppt_ny(data['title'], data['count'])253 # create_ppt(data['title'])254 # try:255 # prs = Presentation('./Final - Presentation.pptx')256 # except exc.PackageNotFoundError as err:257 # # print(f'No presentation file: {err}')258 # prs = Presentation('../../misc/Team_Slide_Custom.pptx')259 # create_team_slide(["chris", "john", "mike", "steve"], BASE_PRESENTATION)260 # res = create_pie_chart({261 # 'req': 'create_pie_chart',262 # 'categories': ['USA', 'Canada', 'Mexico'],263 # 'percentages': ['30', '30', '40']}, BASE_PRESENTATION264 # )265 #266 # res = create_bar_chart({267 # 'req': 'create_bar_chart',268 # 'categories': ['USA', 'Canada', 'Mexico'],269 # 'values': ['81', '45', '54']}, BASE_PRESENTATION270 # )271 #272 # res = create_line_chart({273 # 'req': 'create_line_chart',274 # "Label": ["India", "Bangladesh"],...

Full Screen

Full Screen

create_graph_by_tld.py

Source:create_graph_by_tld.py Github

copy

Full Screen

...16import matplotlib.pyplot as plt17import numpy as np18sys.path.append(os.environ['AIL_BIN'])19from Helper import Process20def create_pie_chart(country ,db_key, date, pie_title, path, save_name):21 monthly_credential_by_tld = server_statistics.hkeys(db_key + date)22 l_tld = []23 for tld in monthly_credential_by_tld:24 nb_tld = server_statistics.hget(db_key + date, tld)25 if nb_tld is not None:26 nb_tld = int(nb_tld)27 else:28 nb_tld = 029 l_tld.append( (tld, nb_tld) )30 mail_tld_top5 = heapq.nlargest(5, l_tld, key=operator.itemgetter(1))31 # Pie chart, where the slices will be ordered and plotted counter-clockwise:32 labels = []33 sizes = []34 explode = [] # only "explode" the 2nd slice (i.e. 'Hogs')35 explode_value = 036 for tld in mail_tld_top5:37 labels.append(tld[0] +' ('+str(tld[1])+')')38 sizes.append(tld[1])39 explode.append(explode_value)40 explode_value = explode_value +0.141 nb_tld = server_statistics.hget(db_key + date, country)42 if nb_tld is not None:43 nb_tld = int(nb_tld)44 else:45 nb_tld = 046 country_label = country + ' ('+str(nb_tld)+')'47 if country_label not in labels:48 labels.append(country_label)49 sizes.append(nb_tld)50 explode.append(explode_value)51 explode = tuple(explode)52 fig1, ax1 = plt.subplots()53 ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',54 shadow=True, startangle=90)55 ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.56 ax1.set_title(pie_title)57 #plt.show()58 plt.savefig(os.path.join(path,save_name))59 plt.close(fig1)60def create_donut_chart(db_key, date, pie_title, path, save_name):61 monthly_credential_by_tld = server_statistics.hkeys(db_key + date)62 print()63 l_tld = []64 for tld in monthly_credential_by_tld:65 nb_tld = server_statistics.hget(db_key + date, tld)66 if nb_tld is not None:67 nb_tld = int(nb_tld)68 else:69 nb_tld = 070 l_tld.append( (tld, nb_tld) )71 mail_tld_top5 = heapq.nlargest(5, l_tld, key=operator.itemgetter(1))72 # Pie chart, where the slices will be ordered and plotted counter-clockwise:73 recipe = []74 data = []75 for tld in mail_tld_top5:76 recipe.append(tld[0])77 data.append(tld[1])78 nb_tld = server_statistics.hget(db_key + date, country)79 if nb_tld is not None:80 nb_tld = int(nb_tld)81 else:82 nb_tld = 083 if country not in recipe:84 recipe.append(country)85 data.append(nb_tld)86 fig1, ax1 = plt.subplots(figsize=(6, 3), subplot_kw=dict(aspect="equal"))87 wedges, texts = ax1.pie(data, wedgeprops=dict(width=0.5), startangle=-40)88 bbox_props = dict(boxstyle="square,pad=0.3", fc="w", ec="k", lw=0.72)89 kw = dict(xycoords='data', textcoords='data', arrowprops=dict(arrowstyle="-"),90 bbox=bbox_props, zorder=0, va="center")91 for i, p in enumerate(wedges):92 ang = (p.theta2 - p.theta1)/2. + p.theta193 y = np.sin(np.deg2rad(ang))94 x = np.cos(np.deg2rad(ang))95 horizontalalignment = {-1: "right", 1: "left"}[int(np.sign(x))]96 connectionstyle = "angle,angleA=0,angleB={}".format(ang)97 kw["arrowprops"].update({"connectionstyle": connectionstyle})98 ax1.annotate(recipe[i], xy=(x, y), xytext=(1.35*np.sign(x), 1.4*y),99 horizontalalignment=horizontalalignment, **kw)100 ax1.set_title(pie_title)101 #plt.show()102 plt.savefig(os.path.join(path, save_name))103 plt.close(fig1)104if __name__ == '__main__':105 parser = argparse.ArgumentParser(106 description='''This script is a part of the Analysis Information Leak107 framework. Create statistics pie charts".''',108 epilog='Example: ./create_lu_graph.py 0 lu now, create_lu_graph.py 0 lu 201807')109 parser.add_argument('type', type=int, default=0,110 help='''The graph type (default 0),111 0: all,112 1: credential_pie,113 2: mail_pie114 3: sqlinjection_pie,115 4: iban_pie,''',116 choices=[0, 1, 2, 3, 4], action='store')117 parser.add_argument('country', type=str, default="lu",118 help='''The country code, lu:default''',119 action='store')120 parser.add_argument('date', type=str, default="now",121 help='''month %Y%m, example: 201810''', action='store')122 args = parser.parse_args()123 path = os.path.join(os.environ['AIL_HOME'], 'doc', 'statistics') # save path124 config_section = 'ARDB_Statistics'125 p = Process(config_section, False)126 # ARDB #127 server_statistics = redis.StrictRedis(128 host=p.config.get("ARDB_Statistics", "host"),129 port=p.config.getint("ARDB_Statistics", "port"),130 db=p.config.getint("ARDB_Statistics", "db"),131 decode_responses=True)132 if args.date == 'now' or len(args.date) != 6:133 date = datetime.datetime.now().strftime("%Y%m")134 else:135 date = args.date136 if args.type == 0:137 create_pie_chart(args.country, 'credential_by_tld:', date, "AIL: Credential leak by tld", path, 'AIL_credential_by_tld.png')138 create_pie_chart(args.country, 'mail_by_tld:', date, "AIL: mail leak by tld", path, 'AIL_mail_by_tld.png')139 create_pie_chart(args.country, 'SQLInjection_by_tld:', date, "AIL: SQLInjection by tld", path, 'AIL_SQLInjection_by_tld.png')140 create_pie_chart(args.country.upper(), 'iban_by_country:', date, "AIL: Iban by country", path, 'AIL_iban_by_country.png')141 elif args.type == 1:142 create_pie_chart(args.country, 'credential_by_tld:', date, "AIL: Credential leak by tld", path, 'AIL_credential_by_tld.png')143 elif args.type == 2:144 create_pie_chart(args.country, 'mail_by_tld:', date, "AIL: mail leak by tld", path, 'AIL_mail_by_tld.png')145 elif args.type == 3:146 create_pie_chart(args.country, 'SQLInjection_by_tld:', date, "AIL: sqlInjection by tld", path, 'AIL_sqlInjectionl_by_tld.png')147 elif args.type == 4:...

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