Free Text Hosting with Python - Freddyt

Sometimes when you develop a program you need to save some data on internet: for example you might need to share some variables between your apps or check if there is an update available. If you don't have a web hosting or you don't want to use it this notepad.cc wrapper is perfect. You just need to copy this class into your program.

import urllib, urllib2
class Note:
    def __init__(self,id):
        self.id=id
        self.page=urllib.urlopen("http://notepad.cc/"+id).read()
        pezzi=self.page.split('<textarea name="contents" id="contents" class="contents " spellcheck="true">')
        p=pezzi[1].split("</textarea>")
        self.cont=p[0]
    def getNote(self):
        return self.cont
    def setNote(self, note):
        url = 'http://notepad.cc/ajax/update_contents/'+self.id
        values = {'contents' : note
        }

        data = urllib.urlencode(values)
        req = urllib2.Request(url, data)
        response = urllib2.urlopen(req)
        the_page = response.read()

The usage is simple:

1- Start creating a new Note object. You have to specify an id, for example "testpython1"

note = Note("testpython1")

2- Now set a value using "setNote" function:

note.setNote("This is a python test!")

3- To get the value use "getNote" function:

print note.getNote()

In this case the output is:

This is a python test!

If you work on this you can make a lot of things like update's systems, chatting and online datasharing.

I'm not responsable for the use that you do of this.

Thanks for reading!


comments powered by Disqus