-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_data.py
76 lines (63 loc) · 2.52 KB
/
write_data.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
71
72
73
74
75
76
import pandas as pd
import audible
def write_column_to_df(list, df, df_column, item_attribute):
for item in list:
if item.is_in_df(df):
row_in_df = df.index[
(df["Audible_Title"].str.contains(item.title, regex=False))
& (df["Audible_Author"].str.contains(item.author, regex=False))
]
df.loc[row_in_df, df_column] = getattr(item, item_attribute)
return df
def main():
"""For testing purposes"""
df = pd.DataFrame(
{
"Audible_Title": pd.Series([], dtype="str"),
"Audible_Subtitle": pd.Series([], dtype="str"),
"Audible_Author": pd.Series([], dtype="str"),
"Audible_Link": pd.Series([], dtype="str"),
"Image_Link": pd.Series([], dtype="str"),
"Audible_Category": pd.Series([], dtype="str"),
"Goodreads_Link": pd.Series([], dtype="str"),
"Amazon_Link": pd.Series([], dtype="str"),
"Goodreads_Rating": pd.Series([], dtype="float"),
"Number_of_Ratings": pd.Series([], dtype="int"),
}
)
book = audible.Book(
"A Tale Dark & Grimm",
"Adam Gidwitz",
"https://www.audible.com/pd/A-Tale-Dark-and-Grimm-Audiobook/0593170881?ref=a_ep_black-_c10_lProduct_1_15&pf_rd_p=1fd5ec62-ec05-48ab-a5dd-5ed59ed56551&pf_rd_r=3BWRZX00QVG28D2QJANV",
"https://m.media-amazon.com/images/I/517e-I5cYeL._SL500_.jpg",
" Kids & Teens, $5 Titles",
None,
"https://www.goodreads.com/book/show/7825557-a-tale-dark-grimm?from_search=true&from_srp=true&qid=Je0lFbkYf6&rank=1",
None,
None,
None,
)
books = []
book.add_to_df(df)
book = audible.Book(
"A Tale Dark & Grimm",
"Adam Gidwitz",
"https://www.audible.com/pd/A-Tale-Dark-and-Grimm-Audiobook/0593170881?ref=a_ep_black-_c10_lProduct_1_15&pf_rd_p=1fd5ec62-ec05-48ab-a5dd-5ed59ed56551&pf_rd_r=3BWRZX00QVG28D2QJANV",
"https://m.media-amazon.com/images/I/517e-I5cYeL._SL500_.jpg",
" Kids & Teens, $5 Titles",
None,
"https://www.goodreads.com/book/show/7825557-a-tale-dark-grimm?from_search=true&from_srp=true&qid=Je0lFbkYf6&rank=1",
None,
"4.07",
"23,228",
)
books.append(book)
df = write_column_to_df(
books, df, "Goodreads_Rating", item_attribute="average_rating"
)
df = write_column_to_df(
books, df, "Number_of_Ratings", item_attribute="num_ratings"
)
print(df)
if __name__ == "__main__":
main()