Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dca1bb0

Browse files
Merge pull request #1073 from photon149/main
Faker API
2 parents 2243062 + 4f5f95d commit dca1bb0

File tree

7 files changed

+127
-0
lines changed

7 files changed

+127
-0
lines changed
12 KB
Loading[フレーム]
12.5 KB
Loading[フレーム]
25.2 KB
Loading[フレーム]
6.33 KB
Loading[フレーム]
12.7 KB
Loading[フレーム]

‎APIScripts/Faker API/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Faker API (Fake Data Generator)
2+
3+
## AIM
4+
To randomly generate fake data for further application
5+
6+
## Purpose
7+
To generate fake data for Data Science purposes or testing purposes [FAKER API](https://fakerapi.it/en)
8+
We can generate fake data related to:
9+
- Address , which includes the street address , city , district, pincode ,etc.
10+
- People , whether male or female , with the inclusion of first name , last name , email id ,etc.
11+
- Credit Card Information , all the factors related to credit cards , like card no . , cvv,card holder name ,etc.
12+
- Location , which includes the latitude and longitude of the location
13+
- Companies : with their name , email address,contact no , location , etc.
14+
<br>
15+
and many more ...
16+
17+
## Short description of package/script
18+
Libraries used in this project are:<br>
19+
- ```requests```:- To get an API call from the website. <br>
20+
- ```json```:- To convert the json data that we got from API to python data.
21+
- ```fakerapi```:- To call in the Faker package to generate fake data
22+
23+
## Workflow of the Project
24+
This project follows the following steps:<br>
25+
- Importing relevant libraries
26+
- Making an API call
27+
- Converting json data to python data
28+
- Accessing the python data to show the records.
29+
30+
## Setup Instructions
31+
In order to run this code in your system, one needs to make sure that relevant libraries are installed, use the following commands for installation:
32+
- ```pip install requests```<br>
33+
- ```pip install json```
34+
35+
## Outputs
36+
<br>
37+
Request call getting 200 means API call successfull
38+
<img src = "Images/example_faker.png"><br>
39+
Fake Address Generation eg
40+
<img src = "Images/address_faker.png"><br>
41+
Fake credit card details generated
42+
<img src = "Images/creditcard_faker.png">
43+
Fake location generation
44+
<img src = "Images/location_faker.png"><br>
45+
Fake People generation
46+
<img src = "Images/user_faker.png"><br>
47+
48+
49+
50+
## Author
51+
[Shiwansh Raj](https://github.com/photon149)

‎APIScripts/Faker API/faker_api.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#Importing required libraries
2+
import fakerapi
3+
import json
4+
import requests
5+
6+
'''
7+
Faker Library is used to create fake data
8+
In it's syntax , Every resource accepts 3 common GET parameters:
9+
_locale
10+
_quantity
11+
_seed
12+
13+
14+
_Locale : This parameter means the language of the API response we want to get and accept the locale format "en_EN".
15+
For example: https://fakerapi.it/api/v1/persons?_locale=en_EN . This example returns people with English names.
16+
17+
_quantity : This parameter means the number of rows we want to obtain and accept only integers.
18+
If you request more than 1000 rows (maximum) the system will return 1000 rows anyway.
19+
Default Value : 10
20+
Min: 1 - Max: 1000
21+
Example : https://fakerapi.it/api/v1/addresses?_quantity=5 This example returns 5 Addresses
22+
23+
_seed : This parameter accept an integer and allows to get always the same results.
24+
So, executing the same request with _seed parameter set to the same value (ex. 12345) the results will never change.
25+
Default Value : null
26+
Example : https://fakerapi.it/api/v1/companies?_seed=12456
27+
28+
'''
29+
30+
#Now we will go through the basic example and discover some of the options Faker provides us to generate random data for
31+
32+
response = requests.get('https://fakerapi.it/api/v1/addresses?_quantity=5')
33+
print(response.status_code)
34+
#To check whether API call is successful(200) or not(404)
35+
36+
print(response.text)
37+
# To access all the content of the website
38+
39+
print(response.url)
40+
# print(response.url) # url of the website to which we made our API call
41+
42+
print("\n\n")
43+
python_data = json.loads(response.text) # Converting json data to python data
44+
# print(type(python_data))
45+
for key in python_data.keys():
46+
print(f'{key} : {python_data[key]}') # Calling the whole data from the API
47+
48+
# In this example 5 Addresses were printed , apart from addresses we will see some other options Faker provides us with.
49+
50+
#Example 1 : Credit Cards
51+
response = requests.get('https://fakerapi.it/api/v1/credit_cards?_quantity=3')
52+
print("\n\n")
53+
python_data = json.loads(response.text) # Converting json data to python data
54+
# print(type(python_data))
55+
for key in python_data.keys():
56+
print(f'{key} : {python_data[key]}')
57+
58+
#In this example we got details of 3 fake credit cards
59+
60+
#Example 2 : Places
61+
response = requests.get('https://fakerapi.it/api/v1/places?_quantity=1')
62+
print("\n\n")
63+
python_data = json.loads(response.text) # Converting json data to python data
64+
# print(type(python_data))
65+
for key in python_data.keys():
66+
print(f'{key} : {python_data[key]}')
67+
# In this example we are generating fake data for any random place with position of their longitude and longitude
68+
69+
#Example 3 : Persons
70+
response = requests.get('https://fakerapi.it/api/v1/users?_quantity=7&_gender=female')
71+
print("\n\n")
72+
python_data = json.loads(response.text) # Converting json data to python data
73+
# print(type(python_data))
74+
for key in python_data.keys():
75+
print(f'{key} : {python_data[key]}')
76+
# In this data of 7 random females are generated , with their firstname, lastname,email,etc.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /