Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Maják
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Maják
Commits
19e50a77
Commit
19e50a77
authored
1 year ago
by
Tomáš Valenta
Browse files
Options
Downloads
Patches
Plain Diff
fix instagram sync - remove leftover settings, improve display, skip videos, log more info
parent
042338db
Branches
Branches containing commit
No related tags found
2 merge requests
!804
Release
,
!794
Fix instagram sync - remove leftover settings, improve display, skip videos, log more info
Pipeline
#13706
passed
1 year ago
Stage: build
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
instagram_utils/models.py
+5
-7
5 additions, 7 deletions
instagram_utils/models.py
instagram_utils/services.py
+8
-10
8 additions, 10 deletions
instagram_utils/services.py
main/models.py
+5
-5
5 additions, 5 deletions
main/models.py
main/static/main/main.js
+1
-1
1 addition, 1 deletion
main/static/main/main.js
with
19 additions
and
23 deletions
instagram_utils/models.py
+
5
−
7
View file @
19e50a77
import
datetime
import
logging
import
mimetypes
import
uuid
from
django.conf
import
settings
from
django.db
import
models
logger
=
logging
.
getLogger
()
def
get_current_datetime
()
->
datetime
.
datetime
:
return
datetime
.
datetime
.
now
(
tz
=
datetime
.
timezone
.
utc
)
...
...
@@ -86,15 +89,10 @@ class InstagramMixin(models.Model):
from
.services
import
InstagramDownloadService
try
:
service
=
InstagramDownloadService
(
app_id
=
settings
.
INSTAGRAM_APP_ID
,
app_secret
=
settings
.
INSTAGRAM_APP_SECRET
,
)
service
=
InstagramDownloadService
()
service
.
perform_update
()
except
Exception
:
logger
.
error
(
"
Instagram post update failed
"
,
exc_info
=
True
)
logger
.
error
(
"
Instagram post update failed
"
,
exc_info
=
True
)
super
().
save
(
*
args
,
**
kwargs
)
...
...
This diff is collapsed.
Click to expand it.
instagram_utils/services.py
+
8
−
10
View file @
19e50a77
...
...
@@ -15,14 +15,6 @@ logger = logging.getLogger()
class
InstagramDownloadService
:
"""
TODO
"""
def
__init__
(
self
,
app_id
:
int
,
app_secret
:
str
):
self
.
app_id
=
app_id
self
.
app_secret
=
app_secret
def
get_usernames
(
self
)
->
list
[
str
]:
access_block
=
MainHomePage
.
objects
.
first
().
instagram_access
...
...
@@ -55,8 +47,12 @@ class InstagramDownloadService:
profile
=
instaloader
.
Profile
.
from_username
(
loader
.
context
,
username
)
for
remote_post
in
profile
.
get_posts
():
# Don't recreate existing posts
if
remote_post
.
is_video
:
logger
.
info
(
"
Instagram post ID %s is a video, skipping.
"
,
remote_post
.
shortcode
)
# Don't recreate existing posts
if
InstagramPost
.
objects
.
filter
(
remote_id
=
remote_post
.
shortcode
).
exists
():
logging
.
info
(
"
Skipping Instagram post ID %s, already exists
"
,
...
...
@@ -83,9 +79,11 @@ class InstagramDownloadService:
logger
.
info
(
"
Saved Instagram post ID %s
"
,
remote_post
.
mediaid
,
remote_post
.
shotcode
,
)
post_position
+=
1
def
perform_update
(
self
)
->
None
:
for
username
in
self
.
get_usernames
():
self
.
parse_media_for_user
(
username
)
This diff is collapsed.
Click to expand it.
main/models.py
+
5
−
5
View file @
19e50a77
...
...
@@ -31,7 +31,7 @@ from wagtailmetadata.models import MetadataPageMixin
from
calendar_utils.models
import
CalendarMixin
from
elections2021.constants
import
REGION_CHOICES
# pozor, import ze sousedního modulu
from
instagram_utils.models
import
Instagram
Post
,
Instagram
Mixin
from
instagram_utils.models
import
Instagram
Mixin
,
Instagram
Post
from
shared.forms
import
SubscribeForm
from
shared.models
import
(
# MenuMixin,
ArticleMixin
,
...
...
@@ -59,7 +59,7 @@ class MainHomePage(
ExtendedMetadataHomePageMixin
,
MetadataPageMixin
,
InstagramMixin
,
Page
Page
,
):
# header
...
...
@@ -222,8 +222,8 @@ class MainHomePage(
author_username__in
=
instagram_username_list
).
order_by
(
"
-timestamp
"
)
context
[
"
instagram_post_list
"
]
=
instagram_post_list
[:
4
]
context
[
"
show_next_instagram_post
"
]
=
len
(
instagram_post_list
)
>
4
context
[
"
instagram_post_list
"
]
=
instagram_post_list
[:
3
]
context
[
"
show_next_instagram_post
"
]
=
len
(
instagram_post_list
)
>
3
context
[
"
regions
"
]
=
REGION_CHOICES
...
...
@@ -272,7 +272,7 @@ class MainHomePage(
author_username__in
=
instagram_username_list
).
order_by
(
"
-timestamp
"
)
instagram_post_paginator
=
Paginator
(
instagram_post_list_queryset
,
4
)
instagram_post_paginator
=
Paginator
(
instagram_post_list_queryset
,
3
)
instagram_post_page
=
instagram_post_paginator
.
get_page
(
request
.
GET
.
get
(
"
page
"
,
1
)
...
...
This diff is collapsed.
Click to expand it.
main/static/main/main.js
+
1
−
1
View file @
19e50a77
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment