Fixing scan when created date is null.

This commit is contained in:
Dessalines 2019-02-07 08:41:15 -08:00
parent ca6c232f4b
commit 238acb3d0c
1 changed files with 5 additions and 4 deletions

View File

@ -5,7 +5,7 @@
torrents_csv="`pwd`/../torrents.csv"
scanned_out="`pwd`/../infohashes_scanned.txt"
tmp_torrent_dir="`pwd`/../tmp_torrents"
tmp_torrent_dir="`pwd`/../tmp_torrents-$RANDOM"
torrent_files_json="`pwd`/../torrent_files.json"
touch $scanned_out
@ -41,7 +41,7 @@ cd $tmp_torrent_dir
ls|parallel -n100 mkdir {#}\;mv {} {#}
for tmp_torrent_dir_sub in *; do
echo "sub dir: $tmp_torrent_dir_sub"
echo "sub dir:$tmp_torrent_dir/$tmp_torrent_dir_sub"
find $tmp_torrent_dir_sub -type f -exec basename {} .torrent \; > names.out
# Delete null torrents from the temp dir
@ -54,11 +54,12 @@ for tmp_torrent_dir_sub in *; do
torrent-tracker-health --torrent "$tmp_torrent_dir_sub"/ > health.out
# Convert the json results to csv format
results=$(jq -r '.results | map([.hash, .name, .length, (.created | .[0:16] | strptime("%Y-%m-%dT%H:%M") | mktime), .seeders, .leechers, .completed, (now | floor)] | join(";")) | join("\n")' health.out)
# Created is sometimes null, and a weird date
results=$(jq -r '.results[] | select (.created != null ) | [.hash, .name, .length, (.created | .[0:16] | strptime("%Y-%m-%dT%H:%M") | mktime), .seeders, .leechers, .completed, (now | floor)] | join(";")' health.out)
# If there are no results
if [ -z "$results" ]; then
echo "There were no results for some reason."
cat health.out
else
echo "Torrents.csv updated with new torrents."
# Update the torrents.csv and infohashes scanned file