07 Apr, 2009, Kayle wrote in the 1st comment:
Votes: 0
Now, I'm not the best with Python. Matter of fact, I'm just kindof tinkering with it, and learning as I go. I started tinkering with the Python RSS Reader that Kiasyn put in the repository here. It used to be the NewsBot on the network before it was replaced by the MegaBot. But anyway. I'm playing with it, and I decided I was going to do something crazy, and try and get it to talk to my MUDs website, and using cookies, report the RSS Feed based on immortal level access to the forums. But to do that, I need to be able to send client side cookies, so the site authenticates that the bot has access to those forums. I've set the Bot up with a Login for the forum, and I've given it the appropriate permissions to see the forums I want it to be able to see. But, I'm failing to grasp working with cookies in Python.

Here's a out of the box copy of the python that I've been tinkering with.
# Uber thanks to http://www.xml.com/lpt/a/2002/12/18/dive...
from xml.dom import minidom

import urllib
import sys

(None, # RSS 0.91, 0.92, 0.93, 0.94, 2.0
'http://purl.org/rss/1.0/', # RSS 1.0
'http://my.netscape.com/rdf/simple/0.9/' # RSS 0.90

def load(rssURL):
return minidom.parse(urllib.urlopen(rssURL))

def getElementsByTagName(node, tagName):
children = node.getElementsByTagName(tagName)
if len(children): return children
return []

def first(node, tagName):
children = getElementsByTagName(node, tagName)
return len(children) and children[0] or None

def textOf(node):
return node and "".join([child.data for child in node.childNodes]) or ""

if __name__ == '__main__':
rssDocument = load(sys.argv[1]);
fileObj = open(sys.argv[2],"w");
for item in getElementsByTagName(rssDocument, 'item'):
fileObj.write( "#POST\n" );
fileObj.write( textOf(first(item,'category')) + "~\n" )
fileObj.write( textOf(first(item,'title')) + "~\n" );
fileObj.write( textOf(first(item,'author')) + "~\n" );
fileObj.write( textOf(first(item,'link')) + "~\n" );
fileObj.write( textOf(first(item,'feedburner:origLink')) + "~\n" );
fileObj.write( "#END\n" );

From what I've been able to find online, It'll need updated to use cookielib and urllib2. But for the life of me, I can't make heads or tails of the urllib2 or cookielib documentation in any kind of way that makes me able to accomplish what I'm attempting to do. I'd found several examples that supposedly worked, but they all required a cookie file in the libwww-perl setCookie3 format, and I have no idea how to even go about making a file in that format. So.. Anyone know what I need to do?
07 Apr, 2009, elanthis wrote in the 2nd comment:
Votes: 0
Just search on how to write cookie headers. They're not particularly complex, though using urllib or the like is better and will save a lot of time.
08 Apr, 2009, Kayle wrote in the 3rd comment:
Votes: 0
I figured urllib2 and cookielib were the safer choice, I just can't seem to get a grasp on how to make them work. I"m wondering though if this would be any easier in a different language, like Lua though.
08 Apr, 2009, elanthis wrote in the 4th comment:
Votes: 0
Probably not. Lua doesn't even come with HTTP libraries – the core Lua distribution is very, very small, compact, and only includes features supported by ANSI C (which does not include sockets of any kind).

A very simple Google search on "urllib python cookies" brings this up as the first result, maybe you should see if it helps: http://www.voidspace.org.uk/python/artic...
08 Apr, 2009, David Haley wrote in the 5th comment:
Votes: 0
IIRC, doing this with LuaSocket is about as easy/hard as doing it with Python's libs. (Didn't we do something like this already in Lua?)
08 Apr, 2009, elanthis wrote in the 6th comment:
Votes: 0
Python doesn't require you to install anything extra and it's more likely to be installed on most web hosts. It's the safer bet for any kind of web development unless you're in explicit control of the environment and don't mind keeping manually-installed Lua libraries updated against any security vulnerabilities reported.

If you want to use Lua, go ahead. if you've already got Python, there's little reason to switch.
08 Apr, 2009, David Haley wrote in the 7th comment:
Votes: 0
Sorry, I was just saying that the Lua solution isn't that different. Of course you have to worry about library availability or local maintenance.
11 Apr, 2009, Kayle wrote in the 8th comment:
Votes: 0
Well, thanks to all who helped with this. Especially Kelvin who gave me a great link that got me thinking along the right track! This is working perfectly now.