aboutsummaryrefslogtreecommitdiff
path: root/app.py
blob: b4a311e075e53f957c32864aad931312a3ada039 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Based on this work : https://dvenkatsagar.github.io/tutorials/python/2015/10/26/ddlv/

# The standard library modules
import os
import sys
import re
import sys
from urllib.parse import unquote

# The BeautifulSoup module
from bs4 import BeautifulSoup

# The selenium module
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

if len(sys.argv) != 2:
    print("Usage:")
    print("    "+str(sys.argv[0]+" <url>"))
    sys.exit()

url = sys.argv[1]

print("Starting...")

driver = webdriver.Firefox()

# Load the feedly search page
driver.get("https://feedly.com/i/discover/sources/search/feed/"+url)

print("Searching...")

# Wait some crappy javascript is loaded
try:
    WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.CLASS_NAME, "item-header")))
except:
    print("Timeout: 5 seconds, nothing found")
    driver.close()
    sys.exit()

# Find the link and go to the feed page information to find the correct feed link
driver.find_element_by_css_selector("a.item-header").click()

parser = BeautifulSoup(driver.page_source,"lxml")

# Get the only title who have an data-uri who is the feed link
for title in parser.find_all('h1'):
    if "data-uri" in title.attrs:
        data_uri = re.sub('^feed%2F', '', title.attrs["data-uri"].split("/")[1])
        # Transform %2F to human readble char and print it
        print("Found: "+str(unquote(data_uri)))

driver.close()