Advertisement
Guest User

Untitled

a guest
Feb 13th, 2023
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 6.95 KB | None | 0 0
  1. Scrapper
  2. Common Requirements
  3.  
  4.     Code must correspond to pep8 (use pycodestyle utility for self-check).
  5.         You can set line lengths up to 120 symbols.
  6.  
  7. Task Description
  8.  
  9. For this task, you can join with an RSS reader using Python 3.10.
  10.  
  11. For the testing, you are going to isolate the parts you will work on. Namely, you are going to work only on the RSS (XML) scrapping part. Your task is to parse the RSS document and provide two formatted outputs: JSON and the standard output.
  12.  
  13. You are going to:
  14.  
  15.     Command line parsing.
  16.     Receive the XML document from the web.
  17.  
  18. Because you can create your own style of formatting, it will be difficult to test you. So, we will provide you with the exact style for the format to ease the testing part.
  19.  
  20. The format of the RSS feed that you are going to parse is RSS 2.0. You can follow the link to get a full understanding of the specification. But in this task, we are asking for the following requirements:
  21.  
  22. <channel>...</channel> <!-- Required tags are <title>, <link>, <description>  but we are asking you to be able to parse <title>, <link>, <description>, <category>, <language>, <lastBuildDate>, <managingEditor>, <pubDate>, <item> -->
  23. <item>...</item> <!-- All of the fields here are optional, but each item should have at least <title> or <description>, but for the purposes of the test we are asking to be able to parse <title>, <author>, <pubDate>, <link>, <category>, <description> -->
  24.  
  25. The order of the RSS items in all the output types should be the following:
  26.  
  27.     For <channel> element:
  28.         <title>
  29.         <link>
  30.         <lastBuildDate>
  31.         <pubDate>
  32.         <language>
  33.         <category> for category in categories
  34.         <managinEditor>
  35.         <description>
  36.         <item> for item in items
  37.     For <item> element:
  38.         <title>
  39.         <author>
  40.         <pubDate>
  41.         <link>
  42.         <category>
  43.         <description>
  44.  
  45. The CLI is going to have the following interface. You can use it for testing purposes when you develop XML document parsing.
  46.  
  47. usage: rss_reader.py [-h] [--json] [--limit LIMIT]
  48.                     source
  49.  
  50. Pure Python command-line RSS reader.
  51.  
  52. positional arguments:
  53.  source         RSS URL
  54.  
  55. optional arguments:
  56.  -h, --help     show this help message and exit
  57.  --json         Print result as JSON in stdout
  58.  --limit LIMIT  Limit news topics if this parameter is provided
  59.  
  60. Command Line Arguments
  61.  
  62.     If the limit is not specified, then the user should get all available feeds.
  63.     If the limit is larger than the feed size, then the user should get all available news.
  64.     The limit argument should also affect JSON generation
  65.     In the case of using the --json argument, your utility should convert the news into the JSON format.
  66.  
  67. Console Output:
  68.  
  69.     For <channel> element:
  70.         <title> is equal to Feed
  71.         <link> is equal to Link
  72.         <lastBuildDate> is equal to Last Build Date
  73.         <pubDate> is equal to Publish Date
  74.         <language> is equal to Language
  75.         <category> for category in categories is equal to Categories: category1, category2
  76.         <managinEditor> is equal to Editor
  77.         <description> is equal to Description
  78.         <item> for item in items each item is separated by a custom separator, and all items within except for the description are stuck together.
  79.     For <item> element:
  80.         <title> is equal to Title
  81.         <author> is equal to Author
  82.         <pubDate> is equal to Published
  83.         <link> is equal to Link
  84.         <category> is equal to Categories: category1, category2
  85.         <description> is on a separate line without any name.
  86.  
  87. For the console output you are looking for the order of things – channel items go first and then the other items. You should also have a space between the channel elements and items. Also, the description within the item should be on the new line, separated by space. For example:
  88.  
  89. Feed: Yahoo News - Latest News & Headlines
  90. Link: https://news.yahoo.com/rss
  91. Description: Yahoo news description
  92.  
  93. Title: Nestor heads into Georgia after tornados damage Florida
  94. Published: Sun, 20 Oct 2019 04:21:44 +0300
  95. Link: https://news.yahoo.com/wet-weekend-tropical-storm-warnings-131131925.html
  96.  
  97. Nestor raced across Georgia as a post-tropical cyclone late Saturday, hours after the former tropical storm spawned a tornado that damaged homes and a school in central Florida while sparing areas of the Florida Panhandle devastated one year earlier by Hurricane Michael. The storm made landfall Saturday on St. Vincent Island, a nature preserve off Florida's northern Gulf Coast in a lightly populated area of the state, the National Hurricane Center said. Nestor was expected to bring 1 to 3 inches of rain to drought-stricken inland areas on its march across a swath of the U.S. Southeast... <--- !!! THIS IS DESCRIPTION !!!
  98.  
  99. Title: Some Other Title
  100. Published: Sun, 20 Oct 2019 04:21:44 +0300
  101. Link: https://some.other.link/some-other-news
  102.  
  103.  
  104. Some other new cool information. <--- !!! THIS IS DESCRIPTION
  105.  
  106. JSON Output:
  107.  
  108. For the JSON output, you are looking for the exact names of the tags. Ask for the pretty output:
  109.  
  110. {
  111.  "title": "Yahoo News - Latest News & Headlines",
  112.  "link": "https://news.yahoo.com/rss",
  113.  "description": "Yahoo news description",
  114.  "items": [
  115.    {
  116.      "title": "Nestor heads into Georgia after tornados damage Florida",
  117.      "pubDate": "Sun, 20 Oct 2019 04:21:44 +0300",
  118.      "link": "https://some.other.link/some-other-news",
  119.      "description": "Nestor raced across Georgia as a post-tropical cyclone late Saturday, hours after the former tropical storm spawned a tornado that damaged homes and a school in central Florida while sparing areas of the Florida Panhandle devastated one year earlier by Hurricane Michael. The storm made landfall Saturday on St. Vincent Island, a nature preserve off Florida's northern Gulf Coast in a lightly populated area of the state, the National Hurricane Center said. Nestor was expected to bring 1 to 3 inches of rain to drought-stricken inland areas on its march across a swath of the U.S. Southeast..."
  120.    },
  121.    {
  122.      "title": "Some other title",
  123.      "pubDate": "Sun, 20 Oct 2019 04:21:44 +0300",
  124.      "link": "https://some.other.link/some-other-news",
  125.      "description": "Some other new cool information."
  126.    }
  127.  ]
  128. }
  129.  
  130. You should have an indent to be equal to two spaces.
  131.  
  132.        Ensure that your app has no encoding issues (meaning symbols like &#39, etc.) when printing news to stdout.
  133.        Ensure that your app has no encoding issues (meaning symbols like &#39, etc.) when printing news to stdout in JSON format.
  134.        The limit argument should also affect JSON generation. *It is preferable to have different custom exceptions for different situations (if needed).
  135.  
  136. Implementations will be checked with the latest CPython interpreter of the 3.10 branch.
  137.  
  138.    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. Code for readability. John F. Woods
  139.  
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement