Use dict to handle quotes (ref #9)

This commit is contained in:
Felix Ableitner 2019-10-31 19:50:23 +01:00
parent 9b1a45d3cc
commit 85f457fc20
2 changed files with 4 additions and 4 deletions

View file

@ -49,14 +49,13 @@ for root, dirs, files in os.walk('quotes/'):
if ext == '.csv': if ext == '.csv':
full_name = os.path.join(root, name) full_name = os.path.join(root, name)
with open(full_name) as csvfile: with open(full_name) as csvfile:
csvreader = csv.reader(csvfile, delimiter=',', quotechar='`', skipinitialspace=True) csvreader = csv.DictReader(csvfile, delimiter=',', quotechar='`', skipinitialspace=True)
quotes += list(csvreader) quotes += list(csvreader)
print('Found %d total quotes' % len(quotes)) print(f"Found {len(quotes)} total quotes")
row = random.choice(quotes) row = random.choice(quotes)
text = f"<p>{row['quote']}</p>&nbsp;&nbsp;&nbsp;&nbsp;- {row['author']}, <a href={row['link']}>{row['linktitle']}</a>"
text = '<p>{}</p>&nbsp;&nbsp;&nbsp;&nbsp;- {}, <a href={}>{}</a>'.format(row[0], row[1], row[2], row[3])
print(text) print(text)
if not args.debug: if not args.debug:

View file

@ -1,3 +1,4 @@
quote,author,link,linktitle
`Workers of the World, Unite!`,`Karl Marx and Frederick Engels`,`http://marxists.org/archive/marx/works/1848/communist-manifesto/ch04.htm#210`,`Communist Manifesto (1848)` `Workers of the World, Unite!`,`Karl Marx and Frederick Engels`,`http://marxists.org/archive/marx/works/1848/communist-manifesto/ch04.htm#210`,`Communist Manifesto (1848)`
`If we have chosen the position in life in which we can most of all work for mankind, no burdens can bow us down, because they are sacrifices for the benefit of all; then we shall experience no petty, limited, selfish joy, but our happiness will belong to millions, our deeds will live on quietly but perpetually at work, and over our ashes will be shed the hot tears of noble people.`,`Karl Marx`,`http://marxists.org/archive/marx/works/1837-pre/letters/37_11_10.htm`,`Letter to His Father (1837)` `If we have chosen the position in life in which we can most of all work for mankind, no burdens can bow us down, because they are sacrifices for the benefit of all; then we shall experience no petty, limited, selfish joy, but our happiness will belong to millions, our deeds will live on quietly but perpetually at work, and over our ashes will be shed the hot tears of noble people.`,`Karl Marx`,`http://marxists.org/archive/marx/works/1837-pre/letters/37_11_10.htm`,`Letter to His Father (1837)`
`History calls those men the greatest who have ennobled themselves by working for the common good; experience acclaims as happiest the man who has made the greatest number of people happy.`,`Karl Marx`,`http://marxists.org/archive/marx/works/1837-pre/letters/37_11_10.htm`,`Letter to His Father (1837)` `History calls those men the greatest who have ennobled themselves by working for the common good; experience acclaims as happiest the man who has made the greatest number of people happy.`,`Karl Marx`,`http://marxists.org/archive/marx/works/1837-pre/letters/37_11_10.htm`,`Letter to His Father (1837)`

1 `Workers of the World, Unite!`,`Karl Marx and Frederick Engels`,`http://marxists.org/archive/marx/works/1848/communist-manifesto/ch04.htm#210`,`Communist Manifesto (1848)` quote,author,link,linktitle
1 quote,author,link,linktitle
2 `Workers of the World, Unite!`,`Karl Marx and Frederick Engels`,`http://marxists.org/archive/marx/works/1848/communist-manifesto/ch04.htm#210`,`Communist Manifesto (1848)` `Workers of the World, Unite!`,`Karl Marx and Frederick Engels`,`http://marxists.org/archive/marx/works/1848/communist-manifesto/ch04.htm#210`,`Communist Manifesto (1848)`
3 `If we have chosen the position in life in which we can most of all work for mankind, no burdens can bow us down, because they are sacrifices for the benefit of all; then we shall experience no petty, limited, selfish joy, but our happiness will belong to millions, our deeds will live on quietly but perpetually at work, and over our ashes will be shed the hot tears of noble people.`,`Karl Marx`,`http://marxists.org/archive/marx/works/1837-pre/letters/37_11_10.htm`,`Letter to His Father (1837)` `If we have chosen the position in life in which we can most of all work for mankind, no burdens can bow us down, because they are sacrifices for the benefit of all; then we shall experience no petty, limited, selfish joy, but our happiness will belong to millions, our deeds will live on quietly but perpetually at work, and over our ashes will be shed the hot tears of noble people.`,`Karl Marx`,`http://marxists.org/archive/marx/works/1837-pre/letters/37_11_10.htm`,`Letter to His Father (1837)`
4 `History calls those men the greatest who have ennobled themselves by working for the common good; experience acclaims as happiest the man who has made the greatest number of people happy.`,`Karl Marx`,`http://marxists.org/archive/marx/works/1837-pre/letters/37_11_10.htm`,`Letter to His Father (1837)` `History calls those men the greatest who have ennobled themselves by working for the common good; experience acclaims as happiest the man who has made the greatest number of people happy.`,`Karl Marx`,`http://marxists.org/archive/marx/works/1837-pre/letters/37_11_10.htm`,`Letter to His Father (1837)`