Skip to content

Commit

Permalink
Merge pull request #67 from jakufort/fix-results-processing
Browse files Browse the repository at this point in the history
fix shows import
  • Loading branch information
xbgmsharp authored Dec 16, 2024
2 parents bf56c0b + a4397e7 commit a258d04
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
*.csv
*.ini
*.pyc

config/
.venv
32 changes: 13 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,12 @@ $ python -V
Python 3.5
```

Install need module dependencies, `python3-openssl` and `jq` are optional
Setup [`venv`](https://docs.python.org/3/library/venv.html) and install dependencies

```
$ apt-get install python3-dateutil python3-simplejson python3-requests python3-openssl jq
```

### On Arch/Manjaro Linux system

Install dependencies with pacman, `python-pyopenssl` and `jq` are optional

```
$ pacman -S python python-dateutil python-simplejson python-requests python-pyopenssl jq
python -m venv .venv
source .venv/bin/activate
pip3 install -r requirements.txt
```

### On Windows system
Expand All @@ -115,10 +109,12 @@ Ensure you are running Python 3
Python 3.5
```

Install need module dependencies
Setup [`venv`](https://docs.python.org/3/library/venv.html) and install dependencies

```
<python dir>\Scripts\pip3.exe install requests simplejson
python -m venv .venv
.venv\Scripts\activate.bat
pip3 install -r requirements.txt
```

### On macOS system
Expand Down Expand Up @@ -146,14 +142,12 @@ $ pip3 install certifi

Open a new Terminal session so that certificates will be available

Install need module dependencies, `pyopenssl` and `jq` are optional
Setup [`venv`](https://docs.python.org/3/library/venv.html) and install dependencies

```shell
$ pip3 install python-dateutil
$ pip3 install simplejson
$ pip3 install requests
$ pip3 install pyopenssl
$ pip3 install jq
```
python -m venv .venv
source .venv/bin/activate
pip3 install -r requirements.txt
```

## Usage
Expand Down
32 changes: 17 additions & 15 deletions import_trakt.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import collections
import pprint
import time
from collections import Counter

pp = pprint.PrettyPrinter(indent=4)

Expand Down Expand Up @@ -449,7 +450,7 @@ def main():

# if IDs make the list into trakt format
data = []
results = {'sentids' : 0, 'added' : 0, 'existing' : 0, 'not_found' : 0}
results = {'sentids' : 0, 'added' : Counter({}), 'updated' : Counter({}), 'not_found' : {}}
if read_ids:
print("Found {0} items to import".format(len(read_ids)))

Expand Down Expand Up @@ -482,12 +483,7 @@ def main():
result = api_add_to_list(options, data)
if result:
print("Result: {0}".format(result))
if 'added' in result and result['added']:
results['added'] += result['added'][options.type]
if 'existing' in result and result['existing']:
results['existing'] += result['existing'][options.type]
if 'not_found' in result and result['not_found']:
results['not_found'] += len(result['not_found'][options.type])
__update_counters(results, result)
data = []
# Import the rest
if len(data) > 0:
Expand All @@ -496,20 +492,26 @@ def main():
result = api_add_to_list(options, data)
if result:
print("Result: {0}".format(result))
if 'added' in result and result['added']:
results['added'] += result['added'][options.type]
if 'existing' in result and result['existing']:
results['existing'] += result['existing'][options.type]
if 'not_found' in result and result['not_found']:
results['not_found'] += len(result['not_found'][options.type])
__update_counters(results, result)
else:
# TODO Read STDIN to ID
print("No items found, nothing to do.")
sys.exit(0)

print("Overall imported {sent} {type}, results added:{added}, existing:{existing}, not_found:{not_found}".format(
print("Overall imported {sent} {type}, results added:{added}, updated:{updated}, not_found:{not_found}".format(
sent=results['sentids'], type=options.type, added=results['added'],
existing=results['existing'], not_found=results['not_found']))
updated=results['updated'], not_found=results['not_found']))

def __update_counters(results, result):
if 'added' in result and result['added']:
results['added'].update(Counter(result['added']))
if 'updated' in result and result['updated']:
results['updated'].update(Counter(result['updated']))
if 'not_found' in result and result['not_found']:
for key, value in result['not_found'].items():
if key not in results['not_found']:
results['not_found'][key] = []
results['not_found'][key].extend(value)

if __name__ == '__main__':
main()
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
python-dateutil
simplejson
requests

0 comments on commit a258d04

Please sign in to comment.