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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
from django.db import models
from django.urls import reverse
from django.utils.html import format_html, format_html_join
from django.utils import timezone
import settings
from products.models import ProductLink
"""
class Feed(models.Model):
name = models.CharField(max_length=255)
feed_url = models.CharField(max_length=512)
slug = models.CharField(max_length=50)
last_polled = models.DateTimeField(blank=True, null=True)
due_poll = models.DateTimeField(default=datetime.datetime(1900, 1, 1)) # default to distant past to put new sources to front of queue
etag = models.CharField(max_length=255, blank=True, null=True)
last_modified = models.CharField(max_length=255, blank=True, null=True) # just pass this back and forward between server and me , no need to parse
last_result = models.CharField(max_length=255,blank=True,null=True)
interval = models.PositiveIntegerField(default=400)
last_success = models.DateTimeField(blank=True, null=True)
last_change = models.DateTimeField(blank=True, null=True)
live = models.BooleanField(default=True)
status_code = models.PositiveIntegerField(default=0)
last_302_url = models.CharField(max_length=512, null=True, blank=True)
last_302_start = models.DateTimeField(null=True, blank=True)
def __str__(self):
return self.name
"""
class PostType(models.IntegerChoices):
REVIEW = 0, ('review')
GUIDE = 1, ('guide')
HOWTO = 2, ('how-to')
class TemplateType(models.IntegerChoices):
STORY = 0, ('story')
GALLERY = 1, ('gallery')
class Post(models.Model):
# an entry in a feed
user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete=models.SET_NULL)
title = models.CharField(max_length=512, blank=True, null=True)
body = models.TextField(blank=True, null=True)
url = models.CharField(max_length=512, blank=True, null=True)
date_last_pub = models.DateField()
guid = models.CharField(max_length=512, blank=True, null=True, db_index=True)
author = models.CharField(max_length=255, blank=True, null=True)
post_type = models.IntegerField(choices=PostType.choices, default=PostType.GUIDE)
template_type = models.IntegerField(choices=TemplateType.choices, default=TemplateType.STORY)
update_frequency = models.BigIntegerField(help_text="In days")
products = models.ManyToManyField(ProductLink, blank=True, null=True)
needs_update = models.BooleanField(default=False)
is_live = models.BooleanField(default=True)
class Meta:
ordering = ('date_last_pub',)
def __str__(self):
return self.title
def time_since_update(self):
td = timezone.localdate() - self.date_last_pub
return td.days
#def get_needs_update(self):
# if self.time_since_update() > self.update_frequency:
# return True
# else:
# return False
def days_overdue(self):
if self.needs_update == True:
return self.time_since_update() - self.update_frequency
else:
return ''
def admin_url(self):
return format_html('<a target="_blank" href="%s">%s</a>' % (self.url, self.url))
admin_link.short_description = 'Link'
def save(self, *args, **kwargs):
td = timezone.localdate() - self.date_last_pub
if td.days > self.update_frequency:
self.needs_update = True
else:
self.needs_update = False
super(Post, self).save()
class Note(models.Model):
title = models.CharField(max_length=400)
url = models.CharField(max_length=400, blank=True, null=True)
body_markdown = models.TextField(blank=True, null=True)
date_created = models.DateTimeField(default=timezone.now)
post = models.ForeignKey(Post, on_delete=models.CASCADE, null=True)
class Meta:
ordering = ('date_created',)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('notes:edit', kwargs={"pk": self.pk})
#URL,This Article,Type,Lead,Previous Leads,Other Testers,Notes/Docs,Last Pub Date,Update Next,Months Since Update,Update Frequency (Months),Updates per year,Prev. Updates,"18 Mo Traffic Trend
'''
row[0] #url
row[1] #title
row[2] #post_type
row[3] #author
row[7] #date_last_pub
row[10] #update_frequency
with open(path) as f:
reader = csv.reader(f)
count = 0
for row in reader:
if count > 1:
if row[2] == "Deals":
# don't care about deals posts
continue
elif row[2] == "Buying Guide":
gtype = PostType.GUIDE
else:
gtype = PostType.HOWTO
if row[10] == "Retired":
continue
else:
print(int(row[10]))
print(gtype)
d = datetime.strptime(row[7], '%m/%d/%Y')
post, created = Post.objects.get_or_create(
title = str(row[1]).strip(),
url = str(row[0]).strip(),
date_last_pub = d,
author = str(row[3]).strip(),
post_type = gtype,
update_frequency = int(row[10]*30),
)
user = User.objects.get(username="luxagraf")
user
<User: luxagraf>
for post in Post.objects.all():
if post.author == "Scott Gilbertson":
post.user = user
post.save()
'''
|