This commit is contained in:
Samuel Clay 2024-12-09 21:33:57 -08:00
parent 284c53e09a
commit ba87788afb
15 changed files with 1394 additions and 51 deletions

View file

@ -1,7 +1,8 @@
import json
import requests
import boto3
import email import email
import json
import boto3
import requests
def lambda_handler(event, context): def lambda_handler(event, context):

View file

@ -10,7 +10,6 @@ from utils import log as logging
class Command(BaseCommand): class Command(BaseCommand):
def add_arguments(self, parser): def add_arguments(self, parser):
parser.add_argument( parser.add_argument(
"-d", "--days", dest="days", nargs=1, type="int", default=365, help="Number of days to go back" "-d", "--days", dest="days", nargs=1, type="int", default=365, help="Number of days to go back"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -746,7 +746,7 @@ def stripe_checkout(request):
if plan == "change_stripe": if plan == "change_stripe":
checkout_session = stripe.billing_portal.Session.create( checkout_session = stripe.billing_portal.Session.create(
customer=request.user.profile.stripe_id, customer=request.user.profile.stripe_id,
return_url="https://%s%s?next=payments" % (domain, reverse('index')), return_url="https://%s%s?next=payments" % (domain, reverse("index")),
) )
return HttpResponseRedirect(checkout_session.url, status=303) return HttpResponseRedirect(checkout_session.url, status=303)
@ -761,8 +761,8 @@ def stripe_checkout(request):
], ],
"mode": "subscription", "mode": "subscription",
"metadata": {"newsblur_user_id": request.user.pk}, "metadata": {"newsblur_user_id": request.user.pk},
"success_url": "https://%s%s" % (domain, reverse('stripe-return')), "success_url": "https://%s%s" % (domain, reverse("stripe-return")),
"cancel_url": "https://%s%s" % (domain, reverse('index')), "cancel_url": "https://%s%s" % (domain, reverse("index")),
} }
if request.user.profile.stripe_id: if request.user.profile.stripe_id:
session_dict["customer"] = request.user.profile.stripe_id session_dict["customer"] = request.user.profile.stripe_id

View file

@ -10,10 +10,10 @@ import urllib.request
from io import BytesIO from io import BytesIO
from socket import error as SocketError from socket import error as SocketError
import numpy as np
import boto3 import boto3
import lxml.html import lxml.html
import numpy import numpy
import numpy as np
import requests import requests
import scipy import scipy
import scipy.cluster import scipy.cluster

View file

@ -1,34 +1,35 @@
import requests import requests
from django.core.management.base import BaseCommand
from django.conf import settings from django.conf import settings
from django.core.management.base import BaseCommand
class Command(BaseCommand): class Command(BaseCommand):
help = 'Delete old TXT records for Let\'s Encrypt from DNSimple' help = "Delete old TXT records for Let's Encrypt from DNSimple"
def handle(self, *args, **kwargs): def handle(self, *args, **kwargs):
API_TOKEN = settings.DNSIMPLE_API_TOKEN API_TOKEN = settings.DNSIMPLE_API_TOKEN
ACCOUNT_ID = settings.DNSIMPLE_ACCOUNT_ID ACCOUNT_ID = settings.DNSIMPLE_ACCOUNT_ID
DOMAIN = "newsblur.com" DOMAIN = "newsblur.com"
LETSECRYPT_PREFIX = '_acme-challenge' LETSECRYPT_PREFIX = "_acme-challenge"
headers = { headers = {
'Authorization': f'Bearer {API_TOKEN}', "Authorization": f"Bearer {API_TOKEN}",
'Accept': 'application/json', "Accept": "application/json",
'Content-Type': 'application/json', "Content-Type": "application/json",
} }
def get_txt_records(): def get_txt_records():
records = [] records = []
page = 1 page = 1
while True: while True:
url = f'https://api.dnsimple.com/v2/{ACCOUNT_ID}/zones/{DOMAIN}/records?page={page}' url = f"https://api.dnsimple.com/v2/{ACCOUNT_ID}/zones/{DOMAIN}/records?page={page}"
response = requests.get(url, headers=headers) response = requests.get(url, headers=headers)
if response.status_code == 200: if response.status_code == 200:
data = response.json().get('data', []) data = response.json().get("data", [])
records.extend(data) records.extend(data)
if 'pagination' in response.json(): if "pagination" in response.json():
pagination = response.json()['pagination'] pagination = response.json()["pagination"]
if pagination['current_page'] < pagination['total_pages']: if pagination["current_page"] < pagination["total_pages"]:
page += 1 page += 1
else: else:
break break
@ -40,17 +41,19 @@ class Command(BaseCommand):
return records return records
def delete_record(record_id): def delete_record(record_id):
url = f'https://api.dnsimple.com/v2/{ACCOUNT_ID}/zones/{DOMAIN}/records/{record_id}' url = f"https://api.dnsimple.com/v2/{ACCOUNT_ID}/zones/{DOMAIN}/records/{record_id}"
response = requests.delete(url, headers=headers) response = requests.delete(url, headers=headers)
if response.status_code == 204: if response.status_code == 204:
self.stdout.write(f"Deleted record {record_id}") self.stdout.write(f"Deleted record {record_id}")
else: else:
self.stderr.write(f"Failed to delete record {record_id}: {response.status_code} {response.text}") self.stderr.write(
f"Failed to delete record {record_id}: {response.status_code} {response.text}"
)
records = get_txt_records() records = get_txt_records()
self.stdout.write(f"Found {len(records)} records") self.stdout.write(f"Found {len(records)} records")
for record in records: for record in records:
# self.stdout.write(f"Record: {record}") # self.stdout.write(f"Record: {record}")
if record['type'] == 'TXT' and record['name'].startswith(LETSECRYPT_PREFIX): if record["type"] == "TXT" and record["name"].startswith(LETSECRYPT_PREFIX):
self.stdout.write(f"Deleting record {record['id']} {record['name']} {record['content']}") self.stdout.write(f"Deleting record {record['id']} {record['name']} {record['content']}")
delete_record(record['id']) delete_record(record["id"])

View file

@ -4,15 +4,14 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('rss_feeds', '0008_feed_archive_count'), ("rss_feeds", "0008_feed_archive_count"),
] ]
operations = [ operations = [
migrations.AddField( migrations.AddField(
model_name='feed', model_name="feed",
name='similar_feeds', name="similar_feeds",
field=models.ManyToManyField(blank=True, related_name='feeds_by_similarity', to='rss_feeds.Feed'), field=models.ManyToManyField(blank=True, related_name="feeds_by_similarity", to="rss_feeds.Feed"),
), ),
] ]

View file

@ -4,15 +4,14 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('rss_feeds', '0009_feed_similar_feeds'), ("rss_feeds", "0009_feed_similar_feeds"),
] ]
operations = [ operations = [
migrations.AddField( migrations.AddField(
model_name='feed', model_name="feed",
name='discover_indexed', name="discover_indexed",
field=models.BooleanField(blank=True, default=None, null=True), field=models.BooleanField(blank=True, default=None, null=True),
), ),
] ]

View file

@ -108,6 +108,7 @@ class Feed(models.Model):
s3_icon = models.BooleanField(default=False, blank=True, null=True) s3_icon = models.BooleanField(default=False, blank=True, null=True)
search_indexed = models.BooleanField(default=None, null=True, blank=True) search_indexed = models.BooleanField(default=None, null=True, blank=True)
discover_indexed = models.BooleanField(default=None, null=True, blank=True) discover_indexed = models.BooleanField(default=None, null=True, blank=True)
discover_archive_indexed = models.BooleanField(default=None, null=True, blank=True)
fs_size_bytes = models.IntegerField(null=True, blank=True) fs_size_bytes = models.IntegerField(null=True, blank=True)
archive_count = models.IntegerField(null=True, blank=True) archive_count = models.IntegerField(null=True, blank=True)
similar_feeds = models.ManyToManyField( similar_feeds = models.ManyToManyField(

View file

@ -56,6 +56,7 @@ idna==2.10
image==1.5.33 image==1.5.33
iniconfig==1.1.1 iniconfig==1.1.1
isodate==0.6.0 isodate==0.6.0
isort==5.13.2
Jinja2==3.1.3 Jinja2==3.1.3
jmespath==0.10.0 jmespath==0.10.0
jsonpickle==2.0.0 jsonpickle==2.0.0

View file

@ -1,11 +1,12 @@
import openai
import tiktoken
import logging import logging
import re import re
from html import unescape from html import unescape
import openai
import tiktoken
from django.conf import settings from django.conf import settings
def setup_openai_model(openai_model): def setup_openai_model(openai_model):
openai.api_key = settings.OPENAI_API_KEY openai.api_key = settings.OPENAI_API_KEY
try: try:

View file

@ -52,7 +52,11 @@ from sentry_sdk import capture_exception, flush
from utils import json_functions as json from utils import json_functions as json
from utils import log as logging from utils import log as logging
from utils.facebook_fetcher import FacebookFetcher from utils.facebook_fetcher import FacebookFetcher
from utils.feed_functions import TimeoutError, strip_underscore_from_feed_address, timelimit from utils.feed_functions import (
TimeoutError,
strip_underscore_from_feed_address,
timelimit,
)
from utils.json_fetcher import JSONFetcher from utils.json_fetcher import JSONFetcher
from utils.story_functions import linkify, pre_process_story, strip_tags from utils.story_functions import linkify, pre_process_story, strip_tags
from utils.twitter_fetcher import TwitterFetcher from utils.twitter_fetcher import TwitterFetcher

View file

@ -9,9 +9,9 @@ import urllib.parse
import urllib.request import urllib.request
import warnings import warnings
from qurl import qurl
from django.utils.encoding import smart_str from django.utils.encoding import smart_str
from django.utils.translation import ungettext from django.utils.translation import ungettext
from qurl import qurl
from utils import log as logging from utils import log as logging