IFB104 – Assignment 2, Part B: Saving Headlines Solved

Category: Tags: , , , , , , , ,
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (1 vote)

Overview
This is the second part of a two-part assignment. This part is worth 4% of your final grade for IFB104. Part A which preceded it was worth 21%. This part is intended as a last-minute extension to the assignment, thereby testing the maintainability of your solution to Part A and your ability to work under time pressure. If you have a neat, clear solution to Part A you will find completing Part B easy. For the whole assignment you will submit only one solution, containing your combined response to both Parts A and B, and you will receive one grade for the whole 25% assignment.
Goal
In pre-computer times avid news readers would clip stories of interest from newspapers and paste them into scrapbooks as a record of recent events. Today we can do the same thing, but more easily and flexibly, by taking advantage of database technology. In Part A of this assignment you built a significant application which allows its users to select and preview headlines from multiple news feeds and export the corresponding stories in full as a web document. Here you will extend your application so that it also allows the previewed headlines to be stored in a database, either for later viewing via a database browser or processing by some other software application. This extension is shown in blue below.

To complete this part of the assignment you must extend the Python code you have written for Part A so that it gives the user the ability to store their currently-selected headlines from all news feeds in the database whenever they want. This involves both extending the GUI and linking your application to an SQLite database, news_log.db.
The database file accompanies these instructions. It contains a single table, selected_stories, which has three fields, headline, news_feed and publica-
tion_date. For each news story currently chosen by the user your program must insert these three values as a new row in the table. Your program should assume the database already exists and the table is empty when it is started. Whenever the user chooses to store the currently-selected headlines, any previous data in the table is overwritten; only the currentlyselected news stories are stored, not previous selections.
Illustrative example
Supplied with these instructions is an empty SQLite database called news_log.db. If you open it in the DB Browser for SQLite or an equivalent tool you will see that it contains a single table, selected_stories, which has three text fields, as shown below.

As supplied, the table in this database is initially empty, as shown below.

In the instructions for Part A we used a demonstration program which we called “The ‘Smooth Blend’ News Mixer”. It allowed its user to preview news stories from multiple sources in a graphical user interface and export the chosen mixture of stories as an HTML document. Now we extend its capabilities so that it additionally allows the user to store the chosen headlines in the database. To illustrate this, consider the following example.
As explained in the Part A instructions, your Python program must allow the user to preview (at least) four news feeds, two “archived” ones that never change, and two “live” ones from the Internet. To allow the user to store specific stories in the database, we have extended our GUI with an additional widget, in this case a push button labelled “Save selections”, as shown by the red arrow below.

When pressed, this button saves the headlines for the user’s current story selections in the database. Assume that at first the user wants to review some of the archived news stories. In the screenshot below the user has selected the top two stories from the archived copy of the Queensland Times, and the top story from Crikey. Headines, sources and publication dates for the three stories selected can be seen in the GUI at the bottom. Neither of these news sources have been updated since the Part A instructions were written, which is why it’s important to let the reader know the original publication dates.

Now assume the user is interested in these particular news events and decides to save them in the database. In this particular GUI design this is done by pressing the “Save selections” button. If we view the database’s contents at this point we see that the previewed information has now been stored in the selected_stories table, as shown below.

The user has now created a mix containing ten news stories in total from four different sources (but this could be as high as 40 stories if the maximum number was chosen from each source). Satisfied with this new selection the user again presses the “Save selections” button. This causes the previous contents of table selected_stories to be overwritten with the new selections. Viewing the database’s contents at this point shows all the selected headlines, as can be seen below.

Finally, to complete the example, we assume our user also exports the selected stories in full as an HTML document, as shown below when viewed in a web browser. Notice that both old “archived” stories and “live” stories are shown. As usual, all the images displayed are links to online files, not files stored on the local computer, so that the exported HTML document is portable across any computing platform.

Your task is to extend your solution to Part A of the assignment with a database storage capability equivalent to that above. However, you do not need to follow the GUI design above. Creativity is encouraged and any solution that is easy to use and provides the user with equivalent functionality is acceptable.
Development hints
Notice that the information to be stored in the database is exactly the same as the information previewed in the GUI. Therefore, you should be able to reuse the same solution for extracting elements from web documents for both the previewing and database storage features of your application.
The SQLite code needed to complete this task is quite simple. Similar examples can be found in the relevant lecture demonstrations and workshop exercise solutions.
Requirements and marking guide
To complete this task you are required to further extend the provided news_aggregator.py template file with your solution to Part B, on top of your solution to Part A, to provide a data storage capability equivalent to that illustrated above.
The extension for Part B must satisfy the following criteria. Marks available are as shown.
• Widget(s) for choosing to store selected headlines (2%). Your GUI must provide some simple, intuitive feature to allow the user to control whether or not the currently selected headlines are stored in the database. A number of solutions are possible, e.g., a pushbutton widget which the user presses in order to save the headlines currently selected, or a “save mode” checkbox or radiobuttons which can be toggled so that the currently-selected headlines are stored automatically whenever a fresh news mix is selected. Either way, the user must have full and clear control over whether or not the headlines are saved in the database.
You must complete this part of the assignment using only basic Python features and the sqlite3 module. It should be possible to complete this task merely by adding code to your existing solution, with little or no change to the code you have already completed in Part A.
If you are unable to complete the whole task, just submit whatever parts you can get working. You will receive partial marks for incomplete solutions.
Supporting material
Accompanying these instructions we have provided a copy of the necessary SQLite database, news_log.db. It contains a single table, selected_stories, which has three fields, headline, news_feed and publication_date. For the purposes of this assignment the definition of the database’s selected_stories table is very simple, merely three fields of type Text, and no primary key for the table is specified.
As supplied the database table is empty. Your solution should assume that this database and its table already exists in the same folder as your Python program. Your Python program does not need to create the database or the table. Before you begin you should confirm that you can open this database with the DB Browser for SQLite or a similar database tool.
As well as the SQLite database, news_log.db, we have provided a very simple “dump” script, news_log.sql, which re-creates the database’s table when executed. You should not need to use this script at all; it should be possible to open the news_log.db file from the DB Browser for SQLite’s “Open Database” menu option. (Do not drag-and-drop the database file into the DB Browser’s GUI. On some platforms this causes the DB Browser to ask for a password, even though the database is not password-protected.) In the highly unlikely event that you need to create a fresh copy of the database using the dump script you can do so easily using the DB Browser’s “Import database from SQL file” menu option. Ensure that you name the resulting database “news_log.db” and remember to write the changes to it after importing the script.
Portability
Deliverables
You should develop your solution by completing and submitting the provided Python template file news_aggregator.py. Submit this in a “zip” archive containing all the files needed to support your application as follows:
1. Your news_aggregator.py solution. Make sure you have completed the statement at the beginning of the Python file to confirm that this is your own individual work by inserting your name and student number in the places indicated. Submissions without a completed statement will be assumed not to be your own work.
2. One or more small image files needed to support your GUI interface, but no other image files.
4. A copy of the news_log.db database as provided with these instructions. Ensure that the database’s selected_stories table is empty when you submit your solution so that the marker can clearly see your Part B solution adding data to it.
Once you have completed your solution and have zipped up these items submit them to Blackboard as a single file. Submit your solution compressed as a “zip” archive. Do not use other compression formats such as “rar” or “7z”.
Apart from working correctly your Python and HTML code must be well-presented and easy to understand, thanks to (sparse) commenting that explains the purpose of significant elements and helpful choices of variable, parameter and function names. Professional presentation of your code will be taken into account when marking this assignment.
If you are unable to solve the whole problem, submit whatever parts you can get working. You will receive partial marks for incomplete solutions.
How to submit your solution