Compare commits

..

No commits in common. "38a68dbd3d97f47695efd73fc9b70b2ce8fcabda" and "5e8e4bab9e58ecb2bfe15c095c972083626664d0" have entirely different histories.

8 changed files with 2 additions and 109 deletions

View File

@ -83,9 +83,6 @@ DATABASES = {
'PASSWORD': config('MYSQL_PASSWORD'),
'HOST': config('MYSQL_HOST'),
'PORT': config('MYSQL_PORT'),
'OPTIONS': {
'charset': 'utf8mb4',
},
}
}

View File

@ -15,9 +15,8 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('core.urls')),
]

View File

@ -1,28 +0,0 @@
# Generated by Django 5.1.3 on 2024-11-14 16:53
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='publicationcache',
name='author_name',
field=models.CharField(default='', max_length=255, verbose_name='Author Name'),
),
migrations.AddField(
model_name='publicationcache',
name='cid',
field=models.CharField(default='', max_length=255, verbose_name='CID'),
),
migrations.AddField(
model_name='publicationcache',
name='uri',
field=models.CharField(default='', max_length=255, verbose_name='URI'),
),
]

View File

@ -32,10 +32,7 @@ class PublicationCache(models.Model):
related_name="cached_publications")
content = models.TextField("Content")
author = models.CharField("Author", max_length=255)
author_name = models.CharField("Author Name", default="", max_length=255)
published_at = models.DateTimeField("Published At")
uri = models.CharField("URI", default="", max_length=255)
cid = models.CharField("CID", default="", max_length=255)
is_unread = models.BooleanField("Unread", default=True)
def mark_as_read(self):

View File

@ -1,7 +0,0 @@
{% for publication in publications %}
<div class="post">
<p><strong>{{ publication.author_name }} ({{ publication.author_handle }})</strong> <span>{{ publication.published_at }}</span></p>
<p>{{ publication.content }}</p>
<a href="{{ publication.uri }}" target="_blank">View post</a>
</div>
{% endfor %}

View File

@ -1,7 +0,0 @@
from django.urls import path
from . import views
urlpatterns = [
path('timeline/<int:user_id>/', views.user_timeline, name='user_timeline'),
]

View File

@ -1,60 +1,3 @@
import requests
from django.shortcuts import render
from django.http import JsonResponse
from .models import PublicationCache, User
from django.conf import settings
from django.db import IntegrityError
def user_timeline(request, user_id):
try:
user = User.objects.get(id=user_id)
headers = {'Authorization': f"Bearer {user.access_token}"}
timeline_url = f"{user.pds_url}/xrpc/app.bsky.feed.getTimeline"
# Realizamos la solicitud al PDS
response = requests.get(timeline_url, headers=headers)
if response.status_code != 200:
return JsonResponse({"error": "Failed to retrieve timeline"}, status=500)
feed_data = response.json()
posts = feed_data.get('feed', [])
for post_data in posts:
post = post_data.get('post', {})
record = post.get('record', {})
author = post.get('author', {})
text = record.get('text', '')
created_at = record.get('createdAt', '')
post_id = post.get('uri', '')
if post_id:
publication, created = PublicationCache.objects.get_or_create(
id=post_id,
user=user,
defaults={
'content': text,
'author': author.get('handle', ''),
'author_name': author.get('displayName', ''),
'published_at': created_at,
'uri': post.get('uri', ''),
'cid': post.get('cid', ''),
}
)
if not created:
publication.content = text
publication.author = author.get('handle', '')
publication.author_name = author.get('displayName', '')
publication.published_at = created_at
publication.uri = post.get('uri', '')
publication.cid = post.get('cid', '')
publication.save()
publications = PublicationCache.objects.filter(user=user).order_by('-published_at')
return render(request, 'core/user_timeline.html', {'publications': publications})
except User.DoesNotExist:
return JsonResponse({"error": "User not found"}, status=404)
except IntegrityError as e:
return JsonResponse({"error": str(e)}, status=500)
# Create your views here.

View File

@ -1,4 +1,3 @@
Django==5.1.3
python-decouple==3.8
mysqlclient==2.2.6
requests==2.32.3