Skip to content

Commit

Permalink
Update repo
Browse files Browse the repository at this point in the history
  • Loading branch information
mirage7714 committed Jun 2, 2023
1 parent 13ea546 commit d2f8ddd
Show file tree
Hide file tree
Showing 41 changed files with 24,750 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
6 changes: 6 additions & 0 deletions .ipynb_checkpoints/Untitled-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web gunicorn app:app
Binary file added __pycache__/bookParser.cpython-36.pyc
Binary file not shown.
Binary file added __pycache__/bookParser.cpython-39.pyc
Binary file not shown.
134 changes: 134 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""

from flask import Flask, request, render_template, send_from_directory
import json
from datetime import datetime
import sqlite3
import requests
from bookParser import parseBookData
import pandas as pd

import json

app = Flask(__name__)
app.static_folder = 'static'

main_url = 'https://sheetdb.io/api/v1/24sxv08ychzzl'
book_url = 'https://sheetdb.io/api/v1/24sxv08ychzzl?sheet=book_list'
history_url = 'https://sheetdb.io/api/v1/24sxv08ychzzl?sheet=book_history'

def getStatistics():
results = {}
history = {}
books = []
book_query = json.loads(requests.get(book_url).text)
history_query = json.loads(requests.get(history_url).text)
for his in history_query:
isbn = his['ISBN']
if isbn in history.keys():
history[isbn] += 1
else:
history[isbn] = 1
for book in book_query:
isbn = book['ISBN']
if isbn in history.keys():
books.append({
'ISBN': isbn,
'Name': book['Name'],
'count': history[isbn]
})
else:
books.append({
'ISBN': isbn,
'Name': book['Name'],
'count': 0
})
return books

def updateHistory(result):
index = len(json.loads(requests.get(history_url).text)) + 1
history_payload = {}
data = []
data.append({
'No': index,
'ISBN': result[0]['ISBN'],
'Name': result[0]['Name'],
'Date': datetime.strftime(datetime.now(), '%Y/%m/%d')
})
history_payload['data'] = data
requests.post(history_url, json = history_payload)

@app.route('/')
def index():
return render_template('index.html')

@app.route('/query_book', methods=['POST'])
def Query():
book = request.form.get('ISBN')
query = json.loads(requests.get(book_url).text)
result = []
for q in query:
if book == q['ISBN']:
result.append({
'ISBN':q['ISBN'],
'Name':q['Name'],
'Author': q['Author'],
'Publisher': q['Publisher'],
'Date': q['Date'],
'Status': q['Status']
})
if (len(result) == 0):
crawlerData = parseBookData(book)
if (len(crawlerData) > 0 ):
result.append({
"ISBN": book,
"Name": crawlerData.split(',')[0],
"Author": crawlerData.split(',')[1],
"Publisher": crawlerData.split(',')[2],
"Date": datetime.strftime(datetime.now(), '%Y/%m/%d'),
'Status': 'In'
})
payload = {}
payload["data"] = result
print(requests.post(book_url, json = payload))
updateHistory(result)
else:
updateHistory(result)
return render_template('book.html',book=book,results=result)

@app.route('/history')
def history():
query = json.loads(requests.get(history_url).text)
result = []
for row in query:
result.append({
'No': row['No'],
'Name': row['Name'],
'ISBN': row['ISBN'],
'Date': row['Date']
})
return render_template('history.html',results=result)

@app.route('/statistics')
def statisticsPage():
result = getStatistics()
return render_template('statistics.html', results = result)

@app.route('/reset')
def reset():
query = json.loads(requests.get(history_url).text)
empty = []
for row in query:
delete_url = 'https://sheetdb.io/api/v1/24sxv08ychzzl?sheet=book_history/ISBN/{}'.format(row['ISBN'])
print(delete_url)
print(requests.delete(delete_url))
return render_template('reset.html',result = empty)


if __name__ == "__main__":
app.run(port=5000, debug = True)
20 changes: 20 additions & 0 deletions bookParser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
"""
Created on Mon May 6 21:28:21 2019
@author: mirag
"""
import requests
from bs4 import BeautifulSoup as soup

def parseBookData(isbn):
url = 'https://search.books.com.tw/search/query/key/{}/cat/all'.format(isbn)
content = soup(requests.get(url).text, 'lxml')
results = content.find_all('li',{'class':'item'})
name = ''
author = ''
if (len(results) > 0 ):
name = results[0].find('a')['title']
author = results[0].find('a',{'rel':'go_author'})['title']
publisher = results[0].find('a',{'rel':'mid_publish'})['title']
return ('{},{},{}'.format(name, author, publisher))
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Flask==0.12.2
Flask-Compress==1.4.0
Flask-Cors==3.0.3
greenlet==0.4.12
gunicorn==19.9.0
1 change: 1 addition & 0 deletions runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.6.3

0 comments on commit d2f8ddd

Please sign in to comment.