Created
March 19, 2013 02:58
-
-
Save scturtle/5193394 to your computer and use it in GitHub Desktop.
use notepad.cc as simple data storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
class Note: | |
def __init__(self, id): | |
self.id = id | |
self.note = None | |
def get_note(self, refresh=False): | |
if refresh or self.note is None: | |
text = requests.get('http://notepad.cc/'+self.id).content | |
self.note = text.split('<textarea name="contents" id="contents"' | |
' class="contents " spellcheck="true">' | |
)[1].split("</textarea>")[0] | |
return self.note | |
def set_note(self, note): | |
requests.post('http://notepad.cc/ajax/update_contents/'+self.id, | |
data={'contents': note}) | |
self.note = note | |
if __name__=='__main__': | |
config = Note('scturtletest') | |
print 'current:', config.get_note() | |
config.set_note('123') | |
print 'set:', config.get_note() | |
requests.post('http://notepad.cc/ajax/update_contents/scturtletest', | |
data={'contents': '456'}) | |
print 'cache:', config.get_note() | |
print 'refreshed:', config.get_note(refresh=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment