Created
February 13, 2011 04:01
-
-
Save ynkdir/824423 to your computer and use it in GitHub Desktop.
sites-upload.py
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
# encoding: utf-8 | |
# require: http://code.google.com/p/gdata-python-client/ | |
from __future__ import print_function, division, unicode_literals, \ | |
absolute_import | |
import sys | |
import os | |
import codecs | |
import getpass | |
import gdata.sites.client | |
import atom | |
SOURCE_APP_NAME = "vimdocjp-updater-v1.1" | |
def main(): | |
site = raw_input("site: ") | |
email = raw_input("email: ") | |
password = getpass.getpass("password: ") | |
client = gdata.sites.client.SitesClient(site) | |
client.client_login(email, password, SOURCE_APP_NAME) | |
uri = "{0}?kind={1}".format(client.MakeContentFeedUri(), "webpage") | |
feed = client.GetContentFeed(uri=uri) | |
entries = {} | |
for entry in feed.entry: | |
page_name = entry.page_name.text | |
if page_name.endswith("-html") or page_name == "home": | |
entries[page_name] = entry | |
for page_name in os.listdir('.'): | |
if page_name.endswith("-html") or page_name == "home": | |
content = open(page_name).read() | |
if page_name in entries: | |
print("update: {0}".format(page_name)) | |
entry = entries.pop(page_name) | |
entry.content = atom.data.Content(text=content) | |
client.Update(entry) | |
else: | |
print("create: {0}".format(page_name)) | |
entry = client.CreatePage("webpage", page_name, | |
html=content, page_name=page_name) | |
for entry in entries.values(): | |
print("delete: {0}".format(entry.page_name.text)) | |
client.Delete(entry) | |
if __name__ == "__main__": | |
# not work with raw_input() | |
#sys.stdin = codecs.getreader(sys.getfilesystemencoding())(sys.stdin) | |
sys.stdout = codecs.getwriter(sys.getfilesystemencoding())(sys.stdout) | |
sys.stderr = codecs.getwriter(sys.getfilesystemencoding())(sys.stderr) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment