-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (64 loc) · 2.44 KB
/
main.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import pandas as pd
#from nlp import Nlp
from reader import Reader
import report
from datetime import date
from datetime import timedelta
import scraper
# Update data and save as opentable_reviews.csv
scraper.scrape()
# Cleaning data
df = pd.read_csv('./opentable_reviews.csv')
df.drop('Unnamed: 0', axis=1, inplace=True)
df.columns = ('review', 'date', 'overall', 'food', 'service', 'ambiance')
today = date.today()
# Weeks may throw KeyError since index is not reset
# Get current week
'''
curr_week = [today.strftime('%Y-%m-%d'),
(today - timedelta(days=1)).strftime('%Y-%m-%d'),
(today - timedelta(days=2)).strftime('%Y-%m-%d'),
(today - timedelta(days=3)).strftime('%Y-%m-%d'),
(today - timedelta(days=4)).strftime('%Y-%m-%d'),
(today - timedelta(days=5)).strftime('%Y-%m-%d'),
(today - timedelta(days=6)).strftime('%Y-%m-%d')]
is_curr_week = df['date'].isin(curr_week)
'''
# Get previous week
'''
prev_week = [(today - timedelta(days=7)).strftime('%Y-%m-%d'),
(today - timedelta(days=8)).strftime('%Y-%m-%d'),
(today - timedelta(days=9)).strftime('%Y-%m-%d'),
(today - timedelta(days=10)).strftime('%Y-%m-%d'),
(today - timedelta(days=11)).strftime('%Y-%m-%d'),
(today - timedelta(days=12)).strftime('%Y-%m-%d'),
(today - timedelta(days=13)).strftime('%Y-%m-%d')]
is_prev_week = df['date'].isin(prev_week)
'''
# Get current month dataframe as curr_month
is_curr_month = list(filter(lambda x: x.split('-')[1] == today.strftime('%m'), df['date']))
curr_month = df[df['date'].isin(is_curr_month)]
curr_month.reset_index(inplace=True)
# Get previous month dataframe as prev_month
prev_month = (today.replace(day=1) - timedelta(days=1)).strftime('%m')
is_prev_month = list(filter(lambda x: x.split('-')[1] == prev_month, df['date']))
prev_month = df[df['date'].isin(is_prev_month)]
prev_month.reset_index(inplace=True)
'''
# Cleaning for sample data
df.drop(['Unnamed: 1', 'Unnamed: 2', 'Unnamed: 3'], axis=1, inplace=True)
df.drop([6, 10], inplace=True)
df.columns = ['Review']
df.reset_index(inplace=True)
df.drop(['index'], axis=1, inplace=True)
'''
# Creating NLP model and predicting reviews
#model = Nlp()
#sentiment = model.predict(df['review'])
#df['sentiment'] = sentiment
# Creating categorizer and printing/saving
#r = Reader(df)
#r.get_categories()
#r.analyze()
report.create_report(df, 'Report All.pdf')
report.create_report(prev_month, 'Report February.pdf')