[Moin-user] moin wiki scripts wanted

Michael Matthews mjmatthews1 at rcn.com
Mon Jan 30 09:05:17 EST 2006


Fredrik Lundh wrote:
> Michael Matthews wrote:
>
>   
>> I was able to find script code to create pages.
>>
>> Looking for script code to:
>>
>> * load attachments.
>> * retrieve page source.
>>     
>
> if URL points to a page, URL?action=raw gives you the source, and
> URL?action=AttachFile&do=get&target=NAME gives you attachment
> NAME, so something like this should work:
>
> import re, urllib
>
> ##
> # Gets the page source for a given moinmoin page.
>
> def get_source(url):
>     action = "?action=raw"
>     return urllib.urlopen(url + action).read()
>
> ##
> # Gets the given attachment.  If target is None, returns "Attachments"
> # page instead.
>
> def get_attachment(url, target=None):
>     action = "?action=AttachFile"
>     if target:
>         action = action + "&do=get&target=" + target
>     return urllib.urlopen(url + action).read()
>
> ##
> # Gets all linked attachments on a given page.
>
> def get_used_attachments(url):
>     attachments = {}
>     for line in get_source(url).split("\n"):
>         if line.startswith("attachment:"):
>             target = line[11:].rstrip("\r\n")
>             attachments[target] = get_attachment(url, target)
>     return attachments
>
> ##
> # Gets all linked attachments on a given page.
>
> def get_all_attachments(url):
>     attachments = {}
>     p = re.compile("do=get&target=([^\"]+)\">")
>     for target in p.findall(get_attachment(url)):
>         attachments[target] = get_attachment(url, target)
>     return attachments
>
> </F>
>
>   
I want to PUT the attachment not get it. I should have said UPLOAD 
attachment.

Actually I found a script to get page source in script market I believe.

thanks




More information about the Moin-user mailing list