ConnectedText
September 08, 2010, 01:12:24 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: SMF - Just Installed!
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Back to the Random Quote idea  (Read 1008 times)
0 Members and 1 Guest are viewing this topic.
gcoulthard
Beta testers
Wizard
*****

Karma: +7/-0
Offline Offline

Posts: 302


View Profile WWW
« on: November 25, 2009, 07:04:55 PM »

Still looking for a good solution for this use-case scenario:

1. Project A stores one quote (or one bible verse, thought-for-the-day, photo or picture, dilbert comic, whatever you want) per topic
2. Project B retrieves random topic from Project A for inclusion in a topic  

Shouldn't this be relatively straight-forward? This would be great for educational applications.

See existing topics also:
http://connectedtext.com/forum/index.php?topic=965.0
http://connectedtext.com/forum/index.php?topic=1195.0
Logged
kuehnm
Beta testers
Master
****

Karma: +14/-0
Offline Offline

Posts: 229


View Profile
« Reply #1 on: March 09, 2010, 02:48:33 PM »

I am not entirely sure whether this is what you want, but it is possible to do the following:

In Project A, you have a topic like this (which refers to a topic that contains quotes). Let's call it y.
Code:
<% Python
import win32com.client
import random
ole  = win32com.client.Dispatch("PWIK.Project")
tpcs = ole.LocateTopic('quotes')
text = tpcs.Text
N    = text.Count - 1
while 1:
  line = text[random.randint(0,N)]
  
  if len(line) > 0:
    print line.encode('utf-8')
    break
%>  


In Project B, you have another topic like this (which refers to verses from the Bible or whatever), let's call it w

Code:
<% Python
import win32com.client
import random
ole  = win32com.client.Dispatch("PWIK.Project")
tpcs = ole.LocateTopic('verses')
text = tpcs.Text
N    = text.Count - 1
while 1:
  line = text[random.randint(0,N)]
  
  if len(line) > 0:
    print line.encode('utf-8')
    break
%>  

You can include y in w or w in y.

((Project A: y)) or whatever.

So you have both a quote, and a verse, and whatever in one topic. (The only thing you have to watch is that the included topic is above the python code, for it does not show up otherwise. No idea, why.)

The topics can also be from the same project. You just need to create a different topic for each one you want to include.

Manfred
« Last Edit: March 09, 2010, 03:00:20 PM by kuehnm » Logged
GabiLaser
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 8


View Profile
« Reply #2 on: July 23, 2010, 03:46:43 AM »


Related to this topic (thread necromancer that i am Smiley ), is it possible, using OLE automation in a plugin, to open a different project from inside the plugin?

I have the following idea: project A stores quotes, each topic a quote, topic category is 'quote'. Any other project would load this new plugin and configure it to load project A, displaying randomly one of the topics marked with category 'quote'. Something like:

(in project x:)

<%fortune project=<path to project a> category=quote %>

What i can see that it's possible now is to use for random selection topics in the same project, marked with category 'quote' (one quote per topic). Or with properties such as 'author', or 'subject'.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!