diff options
author | substantialnoninfringinguser <substantialnoninfringinguser@gmail.com> | 2009-05-13 05:25:17 +0100 |
---|---|---|
committer | substantialnoninfringinguser <substantialnoninfringinguser@gmail.com> | 2009-05-13 05:25:17 +0100 |
commit | 7aee3fb920a1477332d78c8f3fb546da428be6e8 (patch) | |
tree | cdfacfc1ef181881d2ac1c7f4c8d4bce2ec917eb /expo/randomLogbookSentance.py | |
parent | 8c818906b5c1228a6fb411cb96d1bd5f1663b49a (diff) | |
download | troggle-7aee3fb920a1477332d78c8f3fb546da428be6e8.tar.gz troggle-7aee3fb920a1477332d78c8f3fb546da428be6e8.tar.bz2 troggle-7aee3fb920a1477332d78c8f3fb546da428be6e8.zip |
[svn] QM parser now parses Hauchhoehle QMs.py
Photo model added.
Logbook parser now puts mugshots in as photo models, and descriptions from the old folk html pages in as "blurbs" on the person model.
Experimented with eye candy and a random logbook quote generator.
Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8094 by aaron @ 12/31/2008 2:59 AM
Diffstat (limited to 'expo/randomLogbookSentance.py')
-rw-r--r-- | expo/randomLogbookSentance.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/expo/randomLogbookSentance.py b/expo/randomLogbookSentance.py new file mode 100644 index 0000000..d4d3f09 --- /dev/null +++ b/expo/randomLogbookSentance.py @@ -0,0 +1,24 @@ +import troggle.settings as settings
+from django import forms
+from expo.models import LogbookEntry
+import random
+import re
+
+def weighted_choice(lst):
+ n = random.uniform(0,1)
+ for item, weight in lst:
+ if n < weight:
+ break
+ n = n - weight
+ return item
+
+def randomLogbookSentence():
+ #Choose a random logbook entry
+ randSent={}
+ randSent['entry']=LogbookEntry.objects.order_by('?')[0]
+
+ #Choose a random sentence from that entry. Store the sentence as randSent['sentence'], and the number of that sentence in the entry as randSent['number']
+ sentenceList=re.findall('[A-Z].*?\.',randSent['entry'].text)
+ randSent['number']=random.randrange(0,len(sentenceList))
+ randSent['sentence']=sentenceList[randSent['number']]
+ return randSent
\ No newline at end of file |