Skip to content

Commit fb89383

Browse files
fix error when response is not 200
1 parent a9c1566 commit fb89383

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/books_crawler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def from_user_get_books(db_path, data_count, user_id, round):
5454
init_books_table(db_path)
5555
insert_books(db_path, data)
5656

57-
if(start > data.get('total')):
57+
if(start > data.get('total', start)):
5858
return False
5959
return True
6060

@@ -84,7 +84,7 @@ def from_doulist_get_books(db_path, data_count, doulist_id, round):
8484
init_books_table(db_path)
8585
insert_books(db_path, data)
8686

87-
if(start > data.get('total')):
87+
if(start > data.get('total', start)):
8888
return False
8989
return True
9090

@@ -128,10 +128,10 @@ def get_recommendations(db_path, data_count, round):
128128
print(f'-------- round: {round}, start: {start} --------')
129129
print(f'Total book count: {total_book_after}')
130130
print(f'Replaced books count: {replaced_book_count}')
131-
print(f'Response total:{data.get('total')}')
131+
print(f'Response total:{data.get('total', start)}')
132132
print(f"{received_count} Data has been inserted into the SQLite database.")
133133

134-
if(start > data.get('total')):
134+
if(start > data.get('total', start)):
135135
return False
136136
return True
137137

src/movies_crawler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def from_user_get_movies(db_path, data_count, user_id, round):
5454
init_movies_table(db_path)
5555
insert_movies(db_path, data)
5656

57-
if(start > data.get('total')):
57+
if(start > data.get('total', start)):
5858
return False
5959
return True
6060

@@ -84,7 +84,7 @@ def from_doulist_get_movies(db_path, data_count, doulist_id, round):
8484
init_movies_table(db_path)
8585
insert_movies(db_path, data)
8686

87-
if(start > data.get('total')):
87+
if(start > data.get('total', start)):
8888
return False
8989
return True
9090

@@ -128,10 +128,10 @@ def get_recommendations(db_path, data_count, round):
128128
log_message(f'-------- round: {round}, start: {start} --------','movie_log.txt')
129129
log_message(f'Total movie count: {total_movie_after}','movie_log.txt')
130130
log_message(f'Replaced movies count: {replaced_movie_count}','movie_log.txt')
131-
log_message(f'Response total:{data.get('total')}','movie_log.txt')
131+
log_message(f'Response total:{data.get('total', start)}','movie_log.txt')
132132
log_message(f"{received_count} Data has been inserted into the SQLite database.",'movie_log.txt')
133133

134-
if(start > data.get('total')):
134+
if(start > data.get('total', start)):
135135
return False
136136
return True
137137

src/test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from utilities import *
44
from get_headers import *
55
from insert_data import *
6+
from movies_crawler import *
67
# cookies = {
78
# 'bid': '4Xl28mUhvMg',
89
# }
@@ -43,4 +44,5 @@
4344
with open('latest_movies_from_doulist.json','r') as f:
4445
data = json.load(f)
4546
insert_doulists('movies.db', data)
46-
47+
start=10
48+
print(start > data.get('total', start))

0 commit comments

Comments
 (0)