File tree Expand file tree Collapse file tree 4 files changed +18
-7
lines changed
python-sqlite-sqlalchemy/code Expand file tree Collapse file tree 4 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,9 @@ def get_temperature_data(filepath: str) -> Dict:
2525 return data
2626
2727
28- def get_average_temp_by_date (date_string : str , temperature_data : Dict ) -> float :
28+ def get_average_temp_by_date (
29+ date_string : str ,
30+ temperature_data : Dict ) -> float :
2931 """
3032 This function gets the average temperature for all the samples
3133 taken by the students by date
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ def get_average_temp_by_date(date_string, connection):
2626 sql = """
2727 SELECT
2828 avg(value) as average
29- FROM temperature_data
29+ FROM temperature_data
3030 WHERE date between ? and ?
3131 """
3232 result = cursor .execute (sql , (min_date , max_date )).fetchone ()
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ def get_total_number_of_books_by_publishers(connection, direction) -> List:
2626 JOIN book_publisher bp on bp.publisher_id = p.publisher_id
2727 JOIN book b on b.book_id = bp.book_id
2828 GROUP BY publisher_name
29- ORDER BY total_books { direction } ;
29+ ORDER BY total_books { direction } ;
3030 """
3131 result = cursor .execute (sql ).fetchall ()
3232 return result
@@ -49,7 +49,7 @@ def get_total_number_of_authors_by_publishers(connection, direction) -> List:
4949 JOIN author_publisher ap on p.publisher_id = ap.publisher_id
5050 JOIN author a on ap.author_id = a.author_id
5151 GROUP BY publisher_name
52- ORDER BY total_authors { direction } ;
52+ ORDER BY total_authors { direction } ;
5353 """
5454 result = cursor .execute (sql ).fetchall ()
5555 return result
Original file line number Diff line number Diff line change @@ -175,20 +175,29 @@ def main():
175175
176176 # Connect to the database using SqlAlchemy
177177 path = os .path .dirname (os .path .abspath (__file__ ))
178- sqlite_filepath = os .path .join (path , "../../build_data/data/author_book_publisher.db" )
178+ sqlite_filepath = os .path .join (
179+ path ,
180+ "../../build_data/data/author_book_publisher.db"
181+ )
179182 engine = create_engine (f"sqlite:///{ sqlite_filepath } " )
180183 Session = sessionmaker ()
181184 Session .configure (bind = engine )
182185 session = Session ()
183186
184187 # Get the total number of books printed by each publisher
185- total_books_by_publisher = get_total_number_of_books_by_publishers (session , "desc" )
188+ total_books_by_publisher = get_total_number_of_books_by_publishers (
189+ session ,
190+ "desc"
191+ )
186192 for row in total_books_by_publisher :
187193 print (f"Publisher: { row .name } , total books: { row .total_books } " )
188194 print ()
189195
190196 # Get the total number of authors each publisher publishes
191- total_authors_by_publisher = get_total_number_of_authors_by_publishers (session , "desc" )
197+ total_authors_by_publisher = get_total_number_of_authors_by_publishers (
198+ session ,
199+ "desc"
200+ )
192201 for row in total_authors_by_publisher :
193202 print (f"Publisher: { row .name } , total authors: { row .total_authors } " )
194203 print ()
You can’t perform that action at this time.
0 commit comments