diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..6560853 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,186 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config:python.pythonPath}", + "program": "${file}", + "cwd": "${workspaceFolder}", + "env": {}, + "envFile": "${workspaceFolder}/.env", + "debugOptions": [ + "RedirectOutput" + ] + }, + { + "name": "Python: Attach", + "type": "python", + "request": "attach", + "localRoot": "${workspaceFolder}", + "remoteRoot": "${workspaceFolder}", + "port": 3000, + "secret": "my_secret", + "host": "localhost" + }, + { + "name": "Python: Terminal (integrated)", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config:python.pythonPath}", + "program": "${file}", + "cwd": "", + "console": "integratedTerminal", + "env": {}, + "envFile": "${workspaceFolder}/.env", + "debugOptions": [] + }, + { + "name": "Python: Terminal (external)", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config:python.pythonPath}", + "program": "${file}", + "cwd": "", + "console": "externalTerminal", + "env": {}, + "envFile": "${workspaceFolder}/.env", + "debugOptions": [] + }, + { + "name": "Python: Django", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config:python.pythonPath}", + "program": "${workspaceFolder}/manage.py", + "cwd": "${workspaceFolder}", + "args": [ + "runserver", + "--noreload", + "--nothreading" + ], + "env": {}, + "envFile": "${workspaceFolder}/.env", + "debugOptions": [ + "RedirectOutput", + "DjangoDebugging" + ] + }, + { + "name": "Python: Flask (0.11.x or later)", + "type": "python", + "request": "launch", + "stopOnEntry": false, + "pythonPath": "${config:python.pythonPath}", + "program": "fully qualified path fo 'flask' executable. Generally located along with python interpreter", + "cwd": "${workspaceFolder}", + "env": { + "FLASK_APP": "${workspaceFolder}/quickstart/app.py" + }, + "args": [ + "run", + "--no-debugger", + "--no-reload" + ], + "envFile": "${workspaceFolder}/.env", + "debugOptions": [ + "RedirectOutput" + ] + }, + { + "name": "Python: Flask (0.10.x or earlier)", + "type": "python", + "request": "launch", + "stopOnEntry": false, + "pythonPath": "${config:python.pythonPath}", + "program": "${workspaceFolder}/run.py", + "cwd": "${workspaceFolder}", + "args": [], + "env": {}, + "envFile": "${workspaceFolder}/.env", + "debugOptions": [ + "RedirectOutput" + ] + }, + { + "name": "Python: PySpark", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "osx": { + "pythonPath": "${env:SPARK_HOME}/bin/spark-submit" + }, + "windows": { + "pythonPath": "${env:SPARK_HOME}/bin/spark-submit.cmd" + }, + "linux": { + "pythonPath": "${env:SPARK_HOME}/bin/spark-submit" + }, + "program": "${file}", + "cwd": "${workspaceFolder}", + "env": {}, + "envFile": "${workspaceFolder}/.env", + "debugOptions": [ + "RedirectOutput" + ] + }, + { + "name": "Python: Module", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config:python.pythonPath}", + "module": "module.name", + "cwd": "${workspaceFolder}", + "env": {}, + "envFile": "${workspaceFolder}/.env", + "debugOptions": [ + "RedirectOutput" + ] + }, + { + "name": "Python: Pyramid", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config:python.pythonPath}", + "cwd": "${workspaceFolder}", + "env": {}, + "envFile": "${workspaceFolder}/.env", + "args": [ + "${workspaceFolder}/development.ini" + ], + "debugOptions": [ + "RedirectOutput", + "Pyramid" + ] + }, + { + "name": "Python: Watson", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config:python.pythonPath}", + "program": "${workspaceFolder}/console.py", + "cwd": "${workspaceFolder}", + "args": [ + "dev", + "runserver", + "--noreload=True" + ], + "env": {}, + "envFile": "${workspaceFolder}/.env", + "debugOptions": [ + "RedirectOutput" + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..915015d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "python.linting.pylintEnabled": false, + "python.pythonPath": "C:\\Users\\ab\\AppData\\Local\\Programs\\Python\\Python36-32\\python.exe" +} \ No newline at end of file diff --git a/add.php b/add.php index 7bf0138..e3292cf 100644 --- a/add.php +++ b/add.php @@ -13,17 +13,25 @@ if ( } else{ $url = $_POST['url']; - if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) { + // check url is valid + if ( + filter_var($url, FILTER_VALIDATE_URL) === FALSE || + !((parse_url($url, PHP_URL_HOST) == 'rutracker.org')) || + !((parse_url($url, PHP_URL_PATH) == '/forum/viewtopic.php')) || + !((parse_url($url, PHP_URL_QUERY))) + ) { die('Not a valid URL'); } parse_str((parse_url($url, PHP_URL_QUERY)), $url); + if (!isset($url['t'])) + { + die('Not a valid URL'); + } $url = $url['t']; $username = $_POST['telegram']; } -// check url is valid - -// check user already reqested notify about this topic +// check if the same user already reqested notify about the same this topic $stmt = $dbh->query( 'SELECT c.username, u.link FROM `contact` c LEFT JOIN `url` u ON u.id = c.topic_id diff --git a/index.php b/index.html similarity index 93% rename from index.php rename to index.html index 96e14e5..1558d17 100644 --- a/index.php +++ b/index.html @@ -1,22 +1,17 @@ - - - - - - - - Let me know - - - -

Rutracker notifyer

-

I will notify you when interesting for you topic will be updated.

-
-
- - -
- + + + + + Let me know + + + +

Rutracker notifyer

+

I will notify you when interesting for you topic will be updated.

+
+
+ + +
+ \ No newline at end of file diff --git a/updater.py b/updater.py new file mode 100644 index 0000000..c7ad32b --- /dev/null +++ b/updater.py @@ -0,0 +1,45 @@ + +# TODO - config file. +import pymysql.cursors +import urllib.request, json +import datetime as dt + +interval = '1 HOUR' +# Connect to the database +connection = pymysql.connect(host='localhost', + user='root', + db='test', + cursorclass=pymysql.cursors.DictCursor) + +# If u_date which already stored older than fresh u_date +# so going to notify +# Any way update last_check +def check_updates(id, u_date): + with urllib.request.urlopen( + "http://api.rutracker.org/v1/get_tor_topic_data?by=topic_id&val="+id) as url: + data = json.loads(url.read().decode()) + last_check = dt.datetime.now() + new_u_date = dt.datetime.fromtimestamp(int(data['result'][id]['reg_time'])) + if new_u_date > u_date: + print("There is an update. Going to notify.") + + with connection.cursor() as cursor: + # Create a new record + sql = "UPDATE url SET last_check = %s, u_date = %s WHERE link = %s" + cursor.execute(sql, ( + last_check.strftime('%Y-%m-%d %H:%M:%S'), + new_u_date.strftime('%Y-%m-%d %H:%M:%S'), + id)) + connection.commit() + +try: + with connection.cursor() as cursor: + # Read a single record + sql = "SELECT * FROM url WHERE last_check < DATE_SUB(NOW(), INTERVAL %s)" % interval + cursor.execute(sql) + result = cursor.fetchall() + for line in result: + print('Going to check %s. Last check was at %s' % (line['link'], line['last_check'])) + check_updates(line['link'], line['u_date']) +finally: + connection.close() \ No newline at end of file