MCPcopy Create free account
hub / github.com/Owyn/CSS2RSS / css_to_rss

Function css_to_rss

css2rss.py:17–147  ·  view source on GitHub ↗
(item, depth)

Source from the content-addressed store, hash-verified

15from bs4 import BeautifulSoup
16
17def css_to_rss(item, depth):
18 find_links_near = False
19 found_link = None
20 if (not(bDefault_link) and sys.argv[4][0] == '!'):
21 item_link = sys.argv[4][1:]
22 #found_link = item #for the default description - maybe bad idea?
23 if bMulti_enabled and not(bDefault_main_title) and (depth+1 < len(item.select(sys.argv[2]))): # lets count found main titles then if the link is static?
24 find_links_near = True
25 elif aEval[4]:
26 found_link = eval(sys.argv[4])
27 if isinstance(found_link, list) == True:
28 if (link_l := len(found_link)) > depth:
29 if bMulti_enabled and depth+1 < link_l:
30 find_links_near = True
31 found_link = found_link[depth]
32 item_link = found_link['href']
33 else:
34 item_link = found_link['href']
35 elif not(bDefault_link) and (link_l := len(found_link := item.select(sys.argv[4]))) > depth:
36 found_link = found_link[depth]
37 item_link = found_link['href']
38 if bMulti_enabled and depth+1 < link_l:
39 find_links_near = True
40 else:
41 if item.name == "a": #item itself is a link
42 found_link = item
43 item_link = item['href']
44 else: # use 1st link found
45 if bDefault_link:
46 found_link = item.find("a")
47 if found_link:
48 item_link = found_link['href']
49 if not(found_link): # we found something else without a link or we specified a link to find so we don't want 1st found link anymore
50 global found_items_bad_n
51 found_items_bad_n += 1
52 return
53
54 if bFixed_main_title:
55 main_title = sys.argv[2]
56 elif aEval[2]:
57 main_title = eval(sys.argv[2]) # add .text at the end of your eval selector yourself if it's a html element
58 if isinstance(main_title, list) == True:
59 main_title = main_title[depth if len(main_title) > depth else 0]
60 elif not(bDefault_main_title) and (mt_l := len(main_title := item.select(sys.argv[2]))) != 0:
61 main_title = main_title[depth if mt_l > depth else 0].text # not sure if we should look for more main titles?
62 elif found_link:
63 main_title = found_link.text # use the link's text
64 #main_title = item.text # use all the text inside - bad idea
65 else:
66 main_title = ""
67 #raise(ValueError("Title & Link were not found - can't do anything now, please adjust your Title selector: " + sys.argv[2]))
68 global found_items_bad_t
69 found_items_bad_t += 1
70 return
71
72 if bFixed_addon_title:
73 addon_title = sys.argv[5]
74 elif not(bDefault_addon_title):

Callers 1

css2rss.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected