use curl for API query, post and delete

  1. QUERY
    $ curl http://localhost:5000/student/
    $ curl http://localhost:5000/student/?page=1
    $ curl http://localhost:5000/student/?class=1&age=19

  2. UPDATE
    $ curl -X POST -d ‘{"name": "Lily", "age": 17, "class":1, "profile":"Likely"}’ -H "Content-Type: application/json" http://127.0.0.1:5000/student/
    {"age":17,"class":"1","id":8,"name":"Lily","profile":"Likely"}

$ curl -X PATCH -d ‘{"class":3}’ -H "Content-Type: application/json" http://127.0.0.1:5000/student/1
{"age":18,"class":"3","id":1,"name":"\u5f20\u4e09","profile":"\u64c5\u957f\u5b66\u4e60"}

  1. DELETE
    $ curl -X DELETE -H "Content-Type: application/json" http://127.0.0.1:5000/student/8

  2. OTHERS (meta and export)
    $ curl http://127.0.0.1:5000/student/meta
    $ curl -o student.csv http://127.0.0.1:5000/student/?export

Curl Cookbook: https://catonmat.net/cookbooks/curl

create a interactive 3D global with pyecharts

  1. pip install pyecharts
  2. write earth.py as below:
import pyecharts.options as opts
from pyecharts.charts import MapGlobe
from pyecharts.faker import POPULATION
  
data = [x for _, x in POPULATION[1:]]
low, high = min(data), max(data)
c = (
MapGlobe(init_opts=opts.InitOpts(width='300px', height='300px',bg_color='#FFFAFA',))
.add_schema()
.add(
maptype="world",
series_name="World Population",
data_pair=POPULATION[1:],
is_map_symbol_show=True,
label_opts=opts.LabelOpts(is_show=True),
)
.set_global_opts(
title_opts=opts.TitleOpts(title="3D Global"),

visualmap_opts=opts.VisualMapOpts(
min_=low,
max_=high,
range_text=["max", "min"],
is_calculable=True,
range_color=["lightskyblue", "yellow", "orangered"],
)
)
.render("world_map_3d.html")
)

3. python earth.py, it will generate world_map_3d.html file, open it in browser:

Awesome-pyecharts

use python Faker to generate test data for any situation

  1. pip install Faker
  2. test Faker functions:
>>> from faker import Faker
>>> fake = Faker(locale='it_IT')
>>> fake.name()
'Romeo Lanfranchi'
>>> fake.address()
'Piazza Antonio 599 Appartamento 12\nSan Ludovica, 42403 Reggio Emilia (TR)'
>>> fake.ssn()
'YQGCOO12N17H487H'
>>> fake.company()
'Acerbi, Rossini e Viola s.r.l.'
>>> fake.ascii_email()
'campanellaguido@hotmail.it'

3. generate test data with name, password and address

import pymysql
from faker import Faker

conn = pymysql.connect(host="ubuntu2020", port=3306, user="monty", password="password", db="flask201",
                       charset="utf8")

cursor = conn.cursor()
sql1 = """drop table if exists faker_user"""
sql2 = """
create table faker_user(
pid int primary key auto_increment,
username varchar(40),
password varchar(20),
address varchar(100) 
)
"""
cursor.execute(sql1)
cursor.execute(sql2)
fake = Faker("en-US")
for i in range(20):
    sql = """insert into faker_user(username,password,address) 
    values('%s','%s','%s')""" % (fake.name(), fake.password(special_chars=False), fake.address())
    print('NAME:'+fake.name() + '|PASSWORD:'+fake.password(special_chars=False) + '|ADDR:'+fake.address())
    cursor.execute(sql)

conn.commit()
cursor.close()
conn.close()

4. generate a json of 10 students with name students.json that contains student name, address, location coordinates and student roll number

from faker import Faker 
import json            # To create a json file                 
from random import randint      # For student id 
fake = Faker() 
def input_data(x): 
  
    # dictionary 
    student_data ={} 
    for i in range(0, x): 
        student_data[i]={} 
        student_data[i]['id']= randint(1, 100) 
        student_data[i]['name']= fake.name() 
        student_data[i]['address']= fake.address() 
        student_data[i]['latitude']= str(fake.latitude()) 
        student_data[i]['longitude']= str(fake.longitude()) 
    print(student_data) 
  
    # dictionary dumped as json in a json file 
    with open('students.json', 'w') as fp: 
        json.dump(student_data, fp) 
      
def main():
      # Enter number of students 
    number_of_students = 10  
    input_data(number_of_students) 
main() 

C:\Users\zhuby>test_faker.py
{0: {'id': 57, 'name': 'Joshua Russell', 'address': '27726 Reed Bypass Apt. 649\nNelsonburgh, PA 87356', 'latitude': '-86.0037635', 'longitude': '-88.371746'}, 1: {'id': 88, 'name': 'Alexander Carpenter', 'address': '5124 Gonzales Center Apt. 087\nAngelamouth, RI 36493', 'latitude': '87.4800465', 'longitude': '-16.477034'}, 2: {'id': 40, 'name': 'Rachel Miller', 'address': '2878 Curtis Parkways Suite 338\nCarolburgh, OK 27880', 'latitude': '-87.890325', 'longitude': '-98.986404'}, 3: {'id': 72, 'name': 'Jon Graves', 'address': '087 Kelley Ports\nSusanmouth, MN 32402', 'latitude': '-50.9987975', 'longitude': '-145.366978'}, 4: {'id': 1, 'name': 'Joseph Rogers', 'address': '630 Sheryl Underpass\nEast Cheryl, IL 95386', 'latitude': '-62.0369605', 'longitude': '-167.059577'}, 5: {'id': 28, 'name': 'Cheryl Hill', 'address': '6863 Christopher Flats\nNew Angela, OK 10664', 'latitude': '59.4719505', 'longitude': '-73.419133'}, 6: {'id': 93, 'name': 'Sean Robinson', 'address': '911 Gardner Center\nEduardoshire, DC 78317', 'latitude': '7.7988015', 'longitude': '156.459505'}, 7: {'id': 6, 'name': 'Jason Myers', 'address': '9577 Shane Valleys Apt. 973\nNew Peggychester, MI 19213', 'latitude': '27.410656', 'longitude': '71.306510'}, 8: {'id': 100, 'name': 'Lindsay Johnson', 'address': '8592 Kathleen Forge Apt. 490\nBerryhaven, TX 84031', 'latitude': '58.841526', 'longitude': '79.355569'}, 9: {'id': 23, 'name': 'Sandra White', 'address': '93126 Schneider Center Suite 054\nAmandaberg, CA 31652', 'latitude': '25.893303', 'longitude': '113.012125'}}