Skip to content

Commit

Permalink
Merge pull request #10 from prise6/dev
Browse files Browse the repository at this point in the history
Version 0.1.2
  • Loading branch information
prise6 authored May 15, 2020
2 parents 63b4a48 + 489a1f5 commit 35c98cb
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 280 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

notes.txt
scripts/draft.py
scripts/test.py
scripts/migrate.py

config/*.ini
config/indexers.yaml
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ENV USERNAME=mediastrends
ARG PUID=1001
ARG PGID=1001
ARG WORKDIR=/app
ARG VERSION=0.1.1
ARG VERSION=0.1.2
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,18 @@ This image will use an entrypoint to make mediastrends use easier. See dockerhub

_To-do_

## Changelog

### version 0.1.2

* resolve issue #9
* add fields to movies
* execute `scripts/migrate_db_v0.1.1_to_v0.1.2.py` to update database fields

### version 0.1.1

* first version


## Disclaimer

Expand Down
2 changes: 1 addition & 1 deletion docker-compose-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
args:
USER_UID: 1000
WORKDIR: /package
image: mediastrends-core-dev:0.1.1
image: mediastrends-core-dev:0.1.2
container_name: mediastrends-core-dev
user: vscode
volumes:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
build:
context: .
dockerfile: Dockerfile
image: mediastrends-core-prod:0.1.1
image: mediastrends-core-prod:0.1.2
container_name: mediastrends-core-prod
user: root
command: get_movie_trends
Expand Down
15 changes: 9 additions & 6 deletions mediastrends/database/peewee/PDbManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def db_to_movie(db_imdb_obj: PIMDBObject, db_torrents: List[PTorrent]) -> Movie:
movie._extras['rating'] = db_imdb_obj.rating
movie._extras['cover_url'] = db_imdb_obj.cover_url
movie._extras['year'] = db_imdb_obj.year
movie._extras['genres'] = db_imdb_obj.genres.split(';') if db_imdb_obj.genres else db_imdb_obj.genres
movie._extras['language_codes'] = db_imdb_obj.language_codes.split(';') if db_imdb_obj.language_codes else db_imdb_obj.language_codes
return movie

#
Expand Down Expand Up @@ -153,17 +155,18 @@ def imdb_object_to_db(obj: Union[Movie], update=False):
db_imdb_obj = PIMDBObject.get_or_none(imdb_id=obj.imdb_id)
torrents_updated = 0

if not db_imdb_obj:
db_imdb_obj = PIMDBObject.create(
if not db_imdb_obj or update:
force_insert = not db_imdb_obj
db_imdb_obj = PIMDBObject(
imdb_id=obj.imdb_id,
title=obj.title,
rating=obj.rating,
cover_url=obj.cover_url,
year=obj.year
year=obj.year,
genres=';'.join(obj.genres) if obj.genres else None,
language_codes=';'.join(obj.language_codes) if obj.language_codes else None
)
else:
if update:
db_imdb_obj.save()
db_imdb_obj.save(force_insert=force_insert)

if obj.torrents:
info_hashes_to_update = [torrent.info_hash for torrent in obj.torrents]
Expand Down
2 changes: 2 additions & 0 deletions mediastrends/database/peewee/PIMDBObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class PIMDBObject(Model):
rating = FloatField(null=True)
year = IntegerField(null=True)
cover_url = TextField(null=True)
genres = TextField(null=True)
language_codes = TextField(null=True)

class Meta:
database = db_factory.database_proxy
2 changes: 1 addition & 1 deletion mediastrends/stats/StatsScraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ def run_by_batch(self):
for info_hashes in tools.batch(full_infos_hashes_list, self._BATCH_SIZE):
try:
self.run(info_hashes)
except requests.exceptions.RequestException as err:
except (requests.exceptions.RequestException, OSError) as err:
logger.warning(err)
continue
2 changes: 1 addition & 1 deletion mediastrends/tasks/movies.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def compute_trending(test, mindate=None, maxdate=None, **kwargs):
with db_factory.get_instance():
for movie in trendings_movies:
try:
PDbManager.imdb_object_to_db(movie)
PDbManager.imdb_object_to_db(movie, update=True)
except Exception as err:
logger.error('Error during imdb object creation (%s): %s' % (movie.imdb_id, err))
# endregion
Expand Down
1 change: 0 additions & 1 deletion mediastrends/torrent/IMDBObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def __getattr__(self, attr: str):
else:
attr_imdb_data = attr_imdb_call = attr.replace('_', ' ')
if attr_imdb_data not in self.imdb_resource:
# raise ValueError("Movie has no %s" % attr)
return None
self._extras[attr] = self.imdb_resource[attr_imdb_call]
return self._extras.get(attr)
Expand Down
21 changes: 21 additions & 0 deletions scripts/migrate_db_v0.1.1_to_v0.1.2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import peewee
from playhouse.migrate import *
from mediastrends.database.peewee.PIMDBObject import PIMDBObject
from mediastrends import db_factory


def main():
db = db_factory.get_instance()
migrator = SqliteMigrator(db)

genres = TextField(null=True)
language_codes = TextField(null=True)

with db:
migrate(
migrator.add_column('pimdbobject', 'genres', genres),
migrator.add_column('pimdbobject', 'language_codes', language_codes),
)

if __name__ == '__main__':
main()
Loading

0 comments on commit 35c98cb

Please sign in to comment.