Attachment 'RandomBanner-1.9.py'

Download

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