You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
501 B
24 lines
501 B
4 years ago
|
import random
|
||
|
import xml.etree.ElementTree as ET
|
||
|
from urllib.parse import unquote
|
||
|
|
||
|
tree = ET.parse('ebooks2.xml')
|
||
|
root = tree.getroot()
|
||
|
|
||
|
favs = []
|
||
|
|
||
|
for response in root:
|
||
|
url = response.find('{DAV:}href').text
|
||
|
favorite = response.find('{DAV:}propstat')\
|
||
|
.find('{DAV:}prop')\
|
||
|
.find('{http://owncloud.org/ns}favorite').text
|
||
|
|
||
|
if favorite != '1':
|
||
|
continue
|
||
|
|
||
|
quoted = url.split('/')[-2]
|
||
|
name = unquote(quoted)
|
||
|
favs.append(name)
|
||
|
|
||
|
print(random.choice(favs))
|