Revision 303139326565 () - Diff

Link to this snippet: https://friendpaste.com/7dijfZ9vHQmV1UbzV49jf9
Embed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import json
from datetime import datetime

from tumblr import Api

from django.conf import settings
from django.core.management.base import BaseCommand

from blog.models import Post
from people.models import Staff

class Command(BaseCommand):
sites = []
def handle(self, *args, **options):
author = Staff.objects.get(username='goulwen')
try:
self.sites = getattr(settings, 'TUMBLR')
except:
print 'Unable to find the TUMBLR sites to import in the settings'
for site in self.sites:
api = Api(site)
post = api.read()
for post in api.read():
type = post['type']
print 'Add %(slug)s with type %(type)s' % {'slug': post['slug'],
'type': type }
if type == 'link':
p = Post(title = post['link-text'],
slug = post['slug'],
author = author,
body = post['link-description'],
tease = post['link-url'],
allow_comments = False,
created_at = datetime.fromtimestamp(post['unix-timestamp']),
updated_at = datetime.fromtimestamp(post['unix-timestamp']),
published_at = datetime.fromtimestamp(post['unix-timestamp'])
)
p.save()
elif type == 'quote':
p = Post(title = post['quote-text'],
slug = post['slug'],
author = author,
body = post['quote-source'],
allow_comments = False,
created_at = datetime.fromtimestamp(post['unix-timestamp']),
updated_at = datetime.fromtimestamp(post['unix-timestamp']),
published_at = datetime.fromtimestamp(post['unix-timestamp'])
)
p.save()
elif type == 'photo':
p = Post(title = 'Photo',
slug = post['slug'],
author = author,
body = post['photo-caption'],
allow_comments = False,
created_at = datetime.fromtimestamp(post['unix-timestamp']),
updated_at = datetime.fromtimestamp(post['unix-timestamp']),
published_at = datetime.fromtimestamp(post['unix-timestamp'])
)
p.save()
elif type == 'regular':
p = Post(title = post['regular-title'],
slug = post['slug'],
author = author,
body = post['regular-body'],
allow_comments = False,
created_at = datetime.fromtimestamp(post['unix-timestamp']),
updated_at = datetime.fromtimestamp(post['unix-timestamp']),
published_at = datetime.fromtimestamp(post['unix-timestamp'])
)
p.save()
elif type == 'video':
p = Post(title = 'Vidéo',
slug = post['slug'],
author = author,
body = post['video-player'],
tease = post['video-source'],
allow_comments = False,
created_at = datetime.fromtimestamp(post['unix-timestamp']),
updated_at = datetime.fromtimestamp(post['unix-timestamp']),
published_at = datetime.fromtimestamp(post['unix-timestamp'])
)
p.save()