Skip to content
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.

Commit

Permalink
Adds Twitter image to web app
Browse files Browse the repository at this point in the history
  • Loading branch information
cuducos committed Dec 29, 2019
1 parent b52ff79 commit 5496c27
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __post_init__(self):
# shortcuts
self.screen_name = self.target.screen_name
self.total_followers = self.target.followers_count
self.image = self.target.profile_image_url_https

@property

This comment has been minimized.

Copy link
@Mehmetkonuklar1

Mehmetkonuklar1 Jan 30, 2022

@selflovequeenn

def followers(self):
Expand Down
16 changes: 16 additions & 0 deletions web/core/migrations/0006_add_image_field_to_job_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 3.0 on 2019-12-29 18:22

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [("core", "0005_add_related_name_to_account_relationship")]

operations = [
migrations.AddField(
model_name="job",
name="image",
field=models.URLField(blank=True, default=""),
)
]
16 changes: 16 additions & 0 deletions web/core/migrations/0007_fill_image_field_on_job_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 3.0 on 2019-12-29 18:24

from django.db import migrations

from lib.twitter import Twitter


def collect_image_urls(apps, _schema_editor):
for job in apps.get_model("core", "Job").objects.filter(image=""):
job.image = Twitter(job.screen_name).image
job.save()


class Migration(migrations.Migration):
dependencies = [("core", "0006_add_image_field_to_job_model")]
operations = [migrations.RunPython(collect_image_urls)]
1 change: 1 addition & 0 deletions web/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

class Job(models.Model, JobSerializer):
screen_name = LowerCaseCharField(max_length=15, unique=True, db_index=True)
image = models.URLField(default="", blank=True)
total_followers = models.IntegerField(null=True)
celery_task_id = models.CharField(
max_length=155, unique=True, db_index=True, default=None, null=True
Expand Down
1 change: 1 addition & 0 deletions web/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class JobSerializer:
def json(self):
serialized = {
"twitter_account": self.screen_name,
"image": self.image,
"followers": self.total_followers,
"analyzed": self.followers.analyzed().count(),
"analyzed_percent": None,
Expand Down
1 change: 1 addition & 0 deletions web/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def start(pk):
return restart(job)

job.total_followers = twitter.total_followers
job.image = twitter.image
job.save()

try:
Expand Down
5 changes: 4 additions & 1 deletion web/core/tests/test_api_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

class TestApiView(TestCase):
def setUp(self):
self.job = mixer.blend(Job, screen_name="Borsalino")
self.job = mixer.blend(
Job, screen_name="Borsalino", image="https://borsalino.png"
)
accounts = (
mixer.blend(Account, botometer=0.62),
mixer.blend(Account, botometer=0.99),
Expand All @@ -27,6 +29,7 @@ def test_content(self):
user, *_ = contents["data"]
expected = {
"twitter_account": str,
"image": str,
"followers": int,
"analyzed": int,
"analyzed_percent": float,
Expand Down

0 comments on commit 5496c27

Please sign in to comment.