forked from CAVIND46016/Yelp-Dataset-Analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestaurantBusinessIdList.py
30 lines (25 loc) · 1009 Bytes
/
restaurantBusinessIdList.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# dsouza{c, d, m}@indiana.edu
# Fetches a list of restaurant business Id's so that review texts can be filtered easily based on restaurant category only.
import json
""" Business yelp dataset file """
SOURCE = 'yelp_academic_dataset_business.json';
def findNWriteListToTxt(catg):
"""
catg ==> Category
Checks for "categories" column under business dataset and writes only the business id's
based on user entered category 'catg', into a text file.
"""
txt_file = open("restaurantID.txt", "w")
id_list = []
with open(SOURCE, encoding='utf-8', errors = 'replace') as f:
for line in f:
data = json.loads(line);
if(catg in str(data['categories'])):
txt_file.write("{}\n".format(data['business_id']));
txt_file.close();
print("List created successfully.")
def main():
catg = 'Restaurants'
findNWriteListToTxt(catg);
if(__name__ == "__main__"):
main();