Ejemplo n.º 1
0
    def _get_meta(self):
        """Fetch Gist metadata."""

        # Use json data provided if available
        if self._json:
            _meta = self._json
            setattr(self, 'id', _meta['repo'])
        else:
            # Fetch Gist metadata
            _meta_url = GIST_JSON % self.id
            _meta = json.load(urllib2.urlopen(_meta_url))['gists'][0]

        for key, value in _meta.iteritems():

            if key == 'files':
                # Remap file key from API.
                setattr(self, 'filenames', value)
                # Store the {current_name: original_name} mapping.
                setattr(self, '_renames', dict((fn, fn) for fn in value))
            elif key == 'public':
                # Attach booleans
                setattr(self, key, value)
            elif key == 'created_at':
                # Attach datetime
                setattr(self, key, dtime(value))
            else:
                # Attach properties to object
                setattr(self, key, unicode(value))

        return _meta
Ejemplo n.º 2
0
    def _get_meta(self):
        """Fetch Gist metadata."""

        # Use json data provided if available
        if self._json:
            _meta = self._json
            setattr(self, "id", _meta["repo"])
        else:
            # Fetch Gist metadata
            _meta_url = GIST_JSON % self.id
            _meta = json.load(urllib2.urlopen(_meta_url))["gists"][0]

        for key, value in _meta.iteritems():

            if key == "files":
                # Remap file key from API.
                setattr(self, "filenames", value)
                # Store the {current_name: original_name} mapping.
                setattr(self, "_renames", dict((fn, fn) for fn in value))
            elif key == "public":
                # Attach booleans
                setattr(self, key, value)
            elif key == "created_at":
                # Attach datetime
                setattr(self, key, dtime(value))
            else:
                # Attach properties to object
                setattr(self, key, unicode(value))

        return _meta
Ejemplo n.º 3
0
	def to_django(self):

		art = DjangoArticle()
		art.title = self.title
		art.subtitle = self.subtitle
		print self.published
		art.published = dtime(self.published)
		art.author = self.author
		art.content = self.content
		art.ourl = self.url
		art.slug = self.slug


		if len(self.content) > 1000:
			art.save()
		else:
			print('%s had no usable content.' % (self.title if self.title else ''))
Ejemplo n.º 4
0
Archivo: migrate.py Proyecto: zeke/.com

posts = []

try:
    in_file = sys.argv[1]
except IndexError:
    print 'Specify a file.'

parser = lxml.etree.XMLParser(recover=True)  #recovers from bad characters.
tree = lxml.etree.parse(in_file, parser)

for post in tree.iterfind('//item'):
    p = Post()
    p.title = post.find('title').text
    p.published = dtime(post.find('pubDate').text)
    p.content = smart_str(
        post.find('{http://purl.org/rss/1.0/modules/content/}encoded').text)

    posts.append(p)

os.system('mkdir -p content')
os.chdir('content')

for post in posts:
    #print '- %s' % post.title
    #print post.__dict__
    filename = post.published.strftime('%y%m%d-')
    filename = filename + '_'.join(post.title.split()[:5]).lower()
    for char in '?\':.#/':
        filename = filename.replace(char, '')