Skip to content

Commit c385ba1

Browse files
committed
add code
1 parent d7be4aa commit c385ba1

File tree

4 files changed

+82
-1
lines changed

4 files changed

+82
-1
lines changed

doudou/2021-01-10-fake-data/api.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from flask import Flask, jsonify, request
2+
from mimesis.schema import Field, Schema
3+
from mimesis.enums import Gender
4+
5+
app = Flask(__name__)
6+
7+
_ = Field('zh')
8+
schema = Schema(schema=lambda: {
9+
'id': _('uuid'),
10+
'name': _('person.name'),
11+
'version': _('version', pre_release=True),
12+
'timestamp': _('timestamp', posix=False),
13+
'owner': {
14+
'email': _('person.email', domains=['test.com'], key=str.lower),
15+
'token': _('token_hex'),
16+
'creator': _('full_name', gender=Gender.FEMALE)
17+
},
18+
'address': {
19+
'country': _('address.country'),
20+
'province': _('address.province'),
21+
'city': _('address.city')
22+
}
23+
})
24+
25+
26+
@app.route('/apps', methods=('GET',))
27+
def apps_view():
28+
count = request.args.get('count', default=1, type=int)
29+
data = schema.create(iterations=count)
30+
return jsonify(data)
31+
32+
33+
if __name__ == '__main__':
34+
app.run(host='127.0.0.1', port=5200, debug=True)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from faker import Faker
2+
from faker.providers import BaseProvider
3+
4+
faker = Faker(locale='zh_CN')
5+
print(f'name: {faker.name()}')
6+
print(f'address: {faker.address()}')
7+
print(f'date: {faker.date()}')
8+
9+
10+
class MyProvider(BaseProvider):
11+
def foo(self):
12+
return 'bar'
13+
14+
15+
faker.add_provider(MyProvider)
16+
print(f'foo: {faker.foo()}')
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from mimesis import Person
2+
from mimesis import Address
3+
from mimesis import Food
4+
5+
print("#" * 30 + " person " + "#" * 30)
6+
person = Person('zh')
7+
print(f'name: {person.surname() + "" + person.name()}')
8+
print(f'sex: {person.sex()}')
9+
print(f'academic degree: {person.academic_degree()}')
10+
11+
print("*" * 30 + " person data " + "*" * 30)
12+
print('\n'.join(('%s:%s' % item for item in person._data.items())))
13+
14+
print("#" * 30 + " address " + "#" * 30)
15+
address = Address("zh")
16+
print(f'continent: {address.continent()}')
17+
print(f'province: {address.province()}')
18+
print(f'city: {address.city()}')
19+
print(f'street name: {address.street_name()}')
20+
21+
print("*" * 30 + " address data " + "*" * 30)
22+
print('\n'.join(('%s:%s' % item for item in address._data.items())))
23+
24+
print("#" * 30 + " food " + "#" * 30)
25+
food = Food("zh")
26+
print(f'dish: {food.dish()}')
27+
print(f'drink: {food.drink()}')
28+
29+
print("*" * 30 + " food data " + "*" * 30)
30+
print('\n'.join(('%s:%s' % item for item in food._data.items())))

doudou/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ Python技术 公众号文章代码库
2121
+ [Chinese People's Volunteer Army](https://github.com/JustDoPython/python-examples/tree/master/doudou/2020-11-10-resisting-us-aid-korea):中国人民志愿军
2222

2323
### 2021 代码列表
24-
+ [GitHub-Top10](https://github.com/JustDoPython/python-examples/tree/master/doudou/2021-01-02-GitHub-Python-Top10):2020-GitHub-Python-Top10
24+
+ [GitHub-Top10](https://github.com/JustDoPython/python-examples/tree/master/doudou/2021-01-02-GitHub-Python-Top10):2020 GitHub Python 库 TOP10
25+
+ [fake-data](https://github.com/JustDoPython/python-examples/tree/master/doudou/2021-01-10-fake-data):假数据
2526

2627
---
2728

0 commit comments

Comments
 (0)