Switched to tge nebula api

This commit is contained in:
2022-01-12 12:29:27 +01:00
parent 1bce8551e7
commit c7948fcf07
7 changed files with 118 additions and 782 deletions

View File

@ -1,19 +1,61 @@
import datetime
from nebula_rss import __version__, NebulaLoader
from bs4 import BeautifulSoup
def test_version():
assert __version__ == '0.1.0'
assert __version__ == '0.2.0'
def test_video_parsing():
example_div = '<div class="css-14ccti3"><a aria-hidden="true" tabindex="-1" class="css-cvinzg" href="/videos/hai-the-bug-that-created-free-public-wifi-networks-that-didnt-work"><div class="css-1ei3f96"><svg viewBox="0 0 2000 1125" class="css-hnyg4"></svg><div class="css-1i7faai"><picture class="css-0"><source srcset="https://images.watchnebula.com/p/dfbf8ec1-0573-41b0-a69e-ed773b32bfd4.jpeg?height=240&amp; 426w, https://images.watchnebula.com/p/dfbf8ec1-0573-41b0-a69e-ed773b32bfd4.jpeg?height=720&amp; 1280w, https://images.watchnebula.com/p/dfbf8ec1-0573-41b0-a69e-ed773b32bfd4.jpeg?height=1080&amp; 1920w" sizes="(max-width: 414px) 100vw, (max-width: 768px) and (min-width: 415px) 50vw, 440px" type="image/jpeg"><img src="https://images.watchnebula.com/p/dfbf8ec1-0573-41b0-a69e-ed773b32bfd4.jpeg?height=720&amp;" alt="The Bug That Created “Free Public Wifi” Networks That Didnt Work thumbnail" width="2000" height="1125" class="css-1u2fze8"></picture><div class="css-zazjdf"><span class="css-y4yfni">Video length:</span><time datetime="PT5M3S">5:03</time></div></div></div></a><div class="css-xzijep"><a class="css-bu30ts" href="/hai"><picture class="css-0"><source srcset="https://images.watchnebula.com/p/ba3e3488-6c9a-4bb1-a3f7-9ccc05352868.webp?width=16&amp; 16w, https://images.watchnebula.com/p/ba3e3488-6c9a-4bb1-a3f7-9ccc05352868.webp?width=32&amp; 32w, https://images.watchnebula.com/p/ba3e3488-6c9a-4bb1-a3f7-9ccc05352868.webp?width=64&amp; 64w, https://images.watchnebula.com/p/ba3e3488-6c9a-4bb1-a3f7-9ccc05352868.webp?width=128&amp; 128w, https://images.watchnebula.com/p/ba3e3488-6c9a-4bb1-a3f7-9ccc05352868.webp?width=256&amp; 256w, https://images.watchnebula.com/p/ba3e3488-6c9a-4bb1-a3f7-9ccc05352868.webp?width=512&amp; 512w" sizes="36px" type="image/webp"><source srcset="https://images.watchnebula.com/p/ba3e3488-6c9a-4bb1-a3f7-9ccc05352868.jpeg?width=16&amp; 16w, https://images.watchnebula.com/p/ba3e3488-6c9a-4bb1-a3f7-9ccc05352868.jpeg?width=32&amp; 32w, https://images.watchnebula.com/p/ba3e3488-6c9a-4bb1-a3f7-9ccc05352868.jpeg?width=64&amp; 64w, https://images.watchnebula.com/p/ba3e3488-6c9a-4bb1-a3f7-9ccc05352868.jpeg?width=128&amp; 128w, https://images.watchnebula.com/p/ba3e3488-6c9a-4bb1-a3f7-9ccc05352868.jpeg?width=256&amp; 256w, https://images.watchnebula.com/p/ba3e3488-6c9a-4bb1-a3f7-9ccc05352868.jpeg?width=512&amp; 512w" sizes="36px" type="image/jpeg"><img src="https://images.watchnebula.com/p/ba3e3488-6c9a-4bb1-a3f7-9ccc05352868.jpeg?width=64&amp;" alt="Half as Interesting avatar" width="2000" height="2000" class="css-izq1dd"></picture></a><a class="css-1eqy4pw" href="/videos/hai-the-bug-that-created-free-public-wifi-networks-that-didnt-work"><div class="css-1njioi">The Bug That Created “Free Public Wifi” Networks That Didnt Work</div><div class="css-4e1m5a"><span>Half as Interesting</span><span class="css-1go4ftc">•</span><span class="css-y4yfni">Video published:</span><time datetime="2022-01-06T15:39:39.000Z">5 days ago</time></div></a></div></div>' # noqa
soup = BeautifulSoup(example_div, features='lxml')
anchor = soup.div.a
video = NebulaLoader._parse_anchor(anchor)
assert video.title == 'The Bug That Created “Free Public Wifi” Networks That Didnt Work'
assert video.creator == 'Half as Interesting'
assert video.url == 'https://nebula.app/videos/hai-the-bug-that-created-free-public-wifi-networks-that-didnt-work'
assert video.release_at == datetime.datetime(2022, 1, 6, 15, 39, 39, tzinfo=datetime.timezone.utc)
example_response = {
'type': 'video_episode',
'slug': 'wendover-electric-vehicles-battery-problem',
'title': "Electric Vehicles' Battery Problem",
'description': 'Watch Extremities at http://youtube.com/extremities\n\nBuy a Wendover Productions t-shirt: https://standard.tv/collections/wendover-productions/products/wendover-productions-shirt\n\nSubscribe to Half as Interesting (The other channel from Wendover Productions): https://www.youtube.com/halfasinteresting\n\nYoutube: http://www.YouTube.com/WendoverProductions\nInstagram: http://Instagram.com/sam.from.wendover\nTwitter: http://www.Twitter.com/WendoverPro\nSponsorship Enquiries: wendover@standard.tv\nOther emails: sam@wendover.productions\nReddit: http://Reddit.com/r/WendoverProductions\n\nWriting by Sam Denby\nEditing by Alexander Williard\nAnimation by Josh Sherrington\nSound by Graham Haerther \nThumbnail by Simon Buckmaster\n\n[1] https://lighthouse.mq.edu.au/article/july-2020/please-explain-how-lithium-became-a-rock-star\n[2] https://www.forbes.com/sites/rrapier/2020/12/13/the-worlds-top-lithium-producers/?sh=378a13bb5bc6\n[3] https://www.statista.com/statistics/235323/lithium-batteries-top-manufacturers/\n[4] https://www.spglobal.com/platts/en/market-insights/latest-news/energy-transition/121421-commodities-2022-global-lithium-market-to-remain-tight-into-2022\n[5] https://tradingeconomics.com/commodity/cobalt\n[6] https://tradingeconomics.com/commodity/nickel\n[7] https://pubs.usgs.gov/periodicals/mcs2021/mcs2021-lithium.pdf\n[8] https://eplanning.blm.gov/public_projects/1503166/200352542/20030633/250036832/Thacker%20Pass_FEIS_Chapters1-6_508.pdf#page=57\n[9] https://www.nytimes.com/2021/05/06/business/lithium-mining-race.html\n[10] http://gbrw.org/wp-content/uploads/2021/02/Thacker-Pass-PR-final.pdf\n[11] https://www.sierranevadaally.org/2021/05/20/people-of-red-mountain-statement-of-opposition-to-lithium-nevada-corps-proposed-thacker-pass-open-pit-lithium-mine/\n[12] https://thisisreno.com/2021/11/judge-says-no-evidence-of-massacre-at-proposed-mine-site-tribes-say-otherwise/\n[13] https://www.statista.com/statistics/264928/cobalt-mine-production-by-country/\n[14] https://www.spglobal.com/platts/en/market-insights/latest-news/metals/022421-uk-cobalt-free-solid-state-battery-technology-claims-major-cost-efficiencies\n[15] https://www.latimes.com/business/story/2021-11-15/drilling-for-white-gold-is-happening-right-now-at-the-salton-sea', # noqa
'short_description': "Electric Vehicles' Battery Problem",
'duration': 970,
'published_at': '2022-01-11T15:03:33Z',
'channel_slug': 'wendover',
'channel_slugs': ['wendover'],
'channel_title': 'Wendover',
'category_slugs': ['explainers'],
'assets': {
'channel_avatar': {
'16': {
'original': 'https://images.watchnebula.com/p/e040f576-82c5-401d-a754-1600483dc673.jpeg?width=16&',
'webp': 'https://images.watchnebula.com/p/e040f576-82c5-401d-a754-1600483dc673.webp?width=16&'
},
'32': {
'original': 'https://images.watchnebula.com/p/e040f576-82c5-401d-a754-1600483dc673.jpeg?width=32&',
'webp': 'https://images.watchnebula.com/p/e040f576-82c5-401d-a754-1600483dc673.webp?width=32&'
},
'64': {
'original': 'https://images.watchnebula.com/p/e040f576-82c5-401d-a754-1600483dc673.jpeg?width=64&',
'webp': 'https://images.watchnebula.com/p/e040f576-82c5-401d-a754-1600483dc673.webp?width=64&'
},
'128': {
'original': 'https://images.watchnebula.com/p/e040f576-82c5-401d-a754-1600483dc673.jpeg?width=128&',
'webp': 'https://images.watchnebula.com/p/e040f576-82c5-401d-a754-1600483dc673.webp?width=128&'
},
'256': {
'original': 'https://images.watchnebula.com/p/e040f576-82c5-401d-a754-1600483dc673.jpeg?width=256&',
'webp': 'https://images.watchnebula.com/p/e040f576-82c5-401d-a754-1600483dc673.webp?width=256&'
},
'512': {
'original': 'https://images.watchnebula.com/p/e040f576-82c5-401d-a754-1600483dc673.jpeg?width=512&',
'webp': 'https://images.watchnebula.com/p/e040f576-82c5-401d-a754-1600483dc673.webp?width=512&'
}
},
'thumbnail': {'240': {'original': 'https://images.watchnebula.com/p/ffcd9296-2857-469d-9c00-1c7bace3407e.jpeg?height=240&', 'webp': 'https://images.watchnebula.com/p/ffcd9296-2857-469d-9c00-1c7bace3407e.webp?height=240&'}, '480': {'original': 'https://images.watchnebula.com/p/ffcd9296-2857-469d-9c00-1c7bace3407e.jpeg?height=480&', 'webp': 'https://images.watchnebula.com/p/ffcd9296-2857-469d-9c00-1c7bace3407e.webp?height=480&'}, '720': {'original': 'https://images.watchnebula.com/p/ffcd9296-2857-469d-9c00-1c7bace3407e.jpeg?height=720&', 'webp': 'https://images.watchnebula.com/p/ffcd9296-2857-469d-9c00-1c7bace3407e.webp?height=720&'}, '1080': {'original': 'https://images.watchnebula.com/p/ffcd9296-2857-469d-9c00-1c7bace3407e.jpeg?height=1080&', 'webp': 'https://images.watchnebula.com/p/ffcd9296-2857-469d-9c00-1c7bace3407e.webp?height=1080&'}}}, # noqa
'attributes': ['free_sample_eligible'],
'share_url': 'https://nebula.app/videos/wendover-electric-vehicles-battery-problem/',
'channel': None,
'engagement': None,
'zype_id': '61dd99e519d76400018b94b0'
}
video = NebulaLoader._parse_api_response(example_response)
assert video.title == "Electric Vehicles' Battery Problem"
assert video.creator == 'Wendover'
assert video.url == 'https://nebula.app/videos/wendover-electric-vehicles-battery-problem/'
assert video.release_at == datetime.datetime(2022, 1, 11, 15, 3, 33, tzinfo=datetime.timezone.utc)
print(video)