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 json
import boto3
import requests
def lambda_handler(event, context):

View file

@ -10,7 +10,6 @@ from utils import log as logging
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument(
"-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":
checkout_session = stripe.billing_portal.Session.create(
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)
@ -761,8 +761,8 @@ def stripe_checkout(request):
],
"mode": "subscription",
"metadata": {"newsblur_user_id": request.user.pk},
"success_url": "https://%s%s" % (domain, reverse('stripe-return')),
"cancel_url": "https://%s%s" % (domain, reverse('index')),
"success_url": "https://%s%s" % (domain, reverse("stripe-return")),
"cancel_url": "https://%s%s" % (domain, reverse("index")),
}
if 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 socket import error as SocketError
import numpy as np
import boto3
import lxml.html
import numpy
import numpy as np
import requests
import scipy
import scipy.cluster

View file

@ -1,34 +1,35 @@
import requests
from django.core.management.base import BaseCommand
from django.conf import settings
from django.core.management.base import 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):
API_TOKEN = settings.DNSIMPLE_API_TOKEN
ACCOUNT_ID = settings.DNSIMPLE_ACCOUNT_ID
DOMAIN = "newsblur.com"
LETSECRYPT_PREFIX = '_acme-challenge'
LETSECRYPT_PREFIX = "_acme-challenge"
headers = {
'Authorization': f'Bearer {API_TOKEN}',
'Accept': 'application/json',
'Content-Type': 'application/json',
"Authorization": f"Bearer {API_TOKEN}",
"Accept": "application/json",
"Content-Type": "application/json",
}
def get_txt_records():
records = []
page = 1
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)
if response.status_code == 200:
data = response.json().get('data', [])
data = response.json().get("data", [])
records.extend(data)
if 'pagination' in response.json():
pagination = response.json()['pagination']
if pagination['current_page'] < pagination['total_pages']:
if "pagination" in response.json():
pagination = response.json()["pagination"]
if pagination["current_page"] < pagination["total_pages"]:
page += 1
else:
break
@ -40,17 +41,19 @@ class Command(BaseCommand):
return records
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)
if response.status_code == 204:
self.stdout.write(f"Deleted record {record_id}")
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()
self.stdout.write(f"Found {len(records)} records")
for record in records:
# 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']}")
delete_record(record['id'])
delete_record(record["id"])

View file

@ -4,15 +4,14 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('rss_feeds', '0008_feed_archive_count'),
("rss_feeds", "0008_feed_archive_count"),
]
operations = [
migrations.AddField(
model_name='feed',
name='similar_feeds',
field=models.ManyToManyField(blank=True, related_name='feeds_by_similarity', to='rss_feeds.Feed'),
model_name="feed",
name="similar_feeds",
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):
dependencies = [
('rss_feeds', '0009_feed_similar_feeds'),
("rss_feeds", "0009_feed_similar_feeds"),
]
operations = [
migrations.AddField(
model_name='feed',
name='discover_indexed',
model_name="feed",
name="discover_indexed",
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)
search_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)
archive_count = models.IntegerField(null=True, blank=True)
similar_feeds = models.ManyToManyField(

View file

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

View file

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

View file

@ -52,7 +52,11 @@ from sentry_sdk import capture_exception, flush
from utils import json_functions as json
from utils import log as logging
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.story_functions import linkify, pre_process_story, strip_tags
from utils.twitter_fetcher import TwitterFetcher

View file

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