diff options
author | Parker <contact@pkrm.dev> | 2024-03-22 22:09:55 -0500 |
---|---|---|
committer | Parker <contact@pkrm.dev> | 2024-03-22 22:09:55 -0500 |
commit | 237aec245e2a135b848dfd3c8dcf46cb755f08e9 (patch) | |
tree | 743fab39fa561139de64a9784078c1e00d85ee43 /app/commands/number_response_request.py | |
parent | bdc5d1fece0b3ee2ac8805ccee07ef93787eeb3e (diff) |
Large Overhaul - Jellyfin Temp Accounts
Temporary jellyfin accounts can now be made through messaging. Commands were moved out and into their own files and functions for organization.
Diffstat (limited to 'app/commands/number_response_request.py')
-rw-r--r-- | app/commands/number_response_request.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/app/commands/number_response_request.py b/app/commands/number_response_request.py new file mode 100644 index 0000000..bb9958c --- /dev/null +++ b/app/commands/number_response_request.py @@ -0,0 +1,59 @@ +import datetime +import requests +import sqlite3 + +import initialize_variables +from create_message import create_message + + +def number_response_request(from_number, message): + if from_number not in initialize_variables.temp_movie_ids.keys(): + create_message(from_number, "There is no current request that you can decide on. It might be that your /request command timed out due since you took too long to response. Please try again. If this issue persists, please contact Parker.") + return + + # If its been 5 minutes since prompt was sent, alert user of timed out request + if (datetime.datetime.now() - initialize_variables.temp_movie_ids[from_number]['time']).total_seconds() / 60 > 5: + del initialize_variables.temp_movie_ids[from_number] + create_message(from_number, "You waited too long and therefore your request has timed out.\n\nPlease try again by re-running the /request command. If this issue persists, please contact Parker.") + return + + # Otherwise, all checks have been completed + create_message(from_number, "Just a moment while I add your movie to the library...") + movie_number = initialize_variables.numbers_responses[message.strip()] + try: + tmdb_id = initialize_variables.temp_movie_ids[from_number]['ids'][movie_number - 1] + except IndexError: + create_message(from_number, "You did not enter a valid number. Please re-send the /request command and try again. If you believe this is an error, please contact Parker.") + del initialize_variables.temp_movie_ids[from_number] + return + + data = requests.get(f'{initialize_variables.radarr_host_url}/api/v3/movie/lookup/tmdb?tmdbId={tmdb_id}', headers=initialize_variables.headers) + + data = data.json() + movie_title = data['title'] + # Change the qualityProfileId, monitored, and rootFolderPath values + data['qualityProfileId'] = initialize_variables.quality_profile_id + data['monitored'] = True + data['rootFolderPath'] = initialize_variables.root_folder_path + # Send data to Radarr API + response = requests.post(f'{initialize_variables.radarr_host_url}/api/v3/movie', headers=initialize_variables.headers, json=data) + data = response.json() + movie_id = data['id'] + # Send message to user alerting them that the movie was added to the library + create_message(from_number, f"🎉 {data['title']} has been added to the library!\n\nTo check up on the status of your movie(s) send /status - please wait at least 5 minutes before running this command in order to get an accurate time.") + + # After everything is completed, send Radarr a request to search indexers for new movie + requests.post(f'{initialize_variables.radarr_host_url}/api/v3/command', headers=initialize_variables.headers, json={'name': 'MoviesSearch', 'movieIds': [int(movie_id)]}) + + # Add the movie_id to the database so that users can check up on the status of their movie + db = sqlite3.connect(initialize_variables.db_path) + cursor = db.cursor() + cursor.execute(''' + INSERT INTO movies(from_number, movie_id, movie_title) + VALUES(?, ?, ?) + ''', (from_number, movie_id, movie_title)) + db.commit() + db.close() + + del initialize_variables.temp_movie_ids[from_number] + return
\ No newline at end of file |