Attachment 'RandomBanner-1.3.py'

Download

   1 #!/usr/bin/python2.4
   2 # -*- coding: iso-8859-1 -*-
   3 #Author: Igor Támara igor@tamarapatino.org
   4 #Date: 12/04/2006
   5 #No warranties.
   6 """
   7       MoinMoin - Random Banner
   8    Purpose : The purpose of this script is to link to another 
   9    place with a banner, like a webring
  10 
  11    Inputs : Receives an URL of a csv file separated with semicolon 
  12    with three fields :
  13    name of site;url site;url banner
  14 
  15      The second argument is the width of the banner
  16      The third argument is the height of the banner
  17 
  18    Output:  Shows the banner, when you move over the banner it shows 
  19    the legend and finally when you click you are directed to the site.
  20 
  21    Examples :
  22    ||<tablestyle="text-align:center;width:100%">[[RandomBanner(http://servidor.slec.net/~igotam/anillo.txt)]]||
  23    will show any of the records on the file as a banner linking to the site.
  24 
  25    [[RandomBanner(http://servidor.slec.net/~igotam/anillo.txt,200,20)]]
  26    will show a random banner on 200x20 size, linking.
  27 
  28 A file containing the following lines worked for me.
  29 
  30 Slec;http://www.slec.net;http://servidor.slec.net/~igotam/images/banner.gif
  31 Gleducar;http://www.gleducar.org.ar;http://servidor.slec.net/~igotam/images/gledubanner.gif
  32 Educalibre;http://www.educalibre.cl;http://servidor.slec.net/~igotam/images/banner.gif
  33 Structio;http://structio.sourceforge.net;http://structio.sourceforge.net/images/bannerstructio.gif
  34 Flisol;http://www.installfest.info;http://www.linuxpreview.org/images/banners/banner-flisol2006-p1latin.gif
  35 
  36 
  37    Side Notes :
  38    Alternate ways of doing this would include using ImageLink macro with
  39    RandomQuote :) .  I remembered that when I have just finished doing this.
  40    RandomBanner DOES NOT rely on those macros.
  41    
  42    Please check that your file is well constructed.
  43    
  44    Comments :
  45    Are welcome
  46 """
  47 
  48 #Dependencies = ["pages"]
  49 import urllib
  50 import random
  51 
  52 def parseargs(args) :
  53     a=args.split(",")
  54     w=468
  55     h=60
  56     works=0
  57     if len(a)==1 :
  58         txtfile=a[0]
  59         works=1
  60     elif len(a)==3:
  61         txtfile=a[0]
  62         w=a[1]
  63         h=a[2]
  64         works=1
  65     return txtfile,w,h,works
  66 
  67 def mypict(txtfile,width,height) :
  68     f=urllib.urlopen(txtfile)
  69     lines=f.readlines()
  70     text,dest,imageurl=random.choice(lines).split(";")
  71     if imageurl[-1]=="\n" :
  72         imageurl=imageurl[:-1]
  73     return '<a href="%s"><img src="%s" alt="%s %s" title="%s %s" width="%d" height="%d"></a>' % (dest,imageurl,text,dest,text,dest,width,height)
  74 def execute(macro, args):
  75     fine=1
  76     res=""
  77     if len(args)>10 :
  78         txtfile,width,height,fine=parseargs(args)
  79     if fine :
  80         res=mypict(txtfile,width,height)
  81     return macro.formatter.rawHTML(res)

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2006-04-13 06:02:45, 2.6 KB) [[attachment:RandomBanner-1.3.py]]
  • [get | view] (2013-05-12 21:02:00, 2.7 KB) [[attachment:RandomBanner-1.9.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.