Compare commits
No commits in common. "475accc50cad799af39bfe9339001ef2258b54d9" and "31f69856a656460877be0627efa0e9060910ce97" have entirely different histories.
475accc50c
...
31f69856a6
3 changed files with 4 additions and 56 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "kosyncrs"
|
name = "kosyncrs"
|
||||||
version = "2.0.0"
|
version = "1.1.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
@ -28,14 +28,14 @@ Connect to the database as user *kosync* (with psql) and create the database tab
|
||||||
```sql
|
```sql
|
||||||
CREATE TABLE users (
|
CREATE TABLE users (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGSERIAL PRIMARY KEY,
|
||||||
username TEXT UNIQUE NOT NULL,
|
username TEXT NOT NULL,
|
||||||
password TEXT
|
password TEXT
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE progresses (
|
CREATE TABLE progresses (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGSERIAL PRIMARY KEY,
|
||||||
user_id BIGINT,
|
user_id BIGINT,
|
||||||
document TEXT NOT NULL,
|
document TEXT UNIQUE NOT NULL,
|
||||||
progress TEXT NOT NULL,
|
progress TEXT NOT NULL,
|
||||||
percentage REAL NOT NULL,
|
percentage REAL NOT NULL,
|
||||||
device TEXT NOT NULL,
|
device TEXT NOT NULL,
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
import psycopg2
|
|
||||||
import re
|
|
||||||
import redis
|
|
||||||
|
|
||||||
con = redis.Redis()
|
|
||||||
|
|
||||||
pgcon = psycopg2.connect("postgresql://kosync:mypassword@localhost/kosync")
|
|
||||||
pgcur = pgcon.cursor()
|
|
||||||
|
|
||||||
userkeys = con.keys('user:*:key')
|
|
||||||
|
|
||||||
for key in userkeys:
|
|
||||||
key = key.decode('utf-8')
|
|
||||||
match = re.search('user:(.*):key', key)
|
|
||||||
username = match.group(1)
|
|
||||||
password = con.get(key).decode('utf-8')
|
|
||||||
|
|
||||||
documentkeys = con.keys('user:' + username + ':document:*')
|
|
||||||
if len(documentkeys) == 0:
|
|
||||||
print("Skipped:", username)
|
|
||||||
continue
|
|
||||||
|
|
||||||
pgcur.execute("INSERT INTO users (username, password) VALUES (%s, %s) ON CONFLICT (username) DO UPDATE SET username = %s, password = %s",
|
|
||||||
(username, password, username, password))
|
|
||||||
|
|
||||||
pgcur.execute("SELECT id FROM users WHERE username = %s", (username,))
|
|
||||||
res = pgcur.fetchone()
|
|
||||||
user_id = res[0]
|
|
||||||
|
|
||||||
for dockey in documentkeys:
|
|
||||||
dockey = dockey.decode('utf-8')
|
|
||||||
|
|
||||||
match = re.search("user:.*:(.*)", dockey)
|
|
||||||
document = match.group(1)
|
|
||||||
|
|
||||||
docvals = con.hgetall(dockey)
|
|
||||||
|
|
||||||
progress = docvals[b"progress"].decode()
|
|
||||||
percentage = docvals[b"percentage"].decode()
|
|
||||||
device = docvals[b"device"].decode()
|
|
||||||
device_id = docvals[b"device_id"].decode()
|
|
||||||
timestamp = docvals[b"timestamp"].decode()
|
|
||||||
|
|
||||||
pgcur.execute("INSERT INTO progresses (user_id, document, progress, percentage, device, device_id, timestamp) VALUES (%s, %s, %s, %s, %s, %s, %s) ON CONFLICT (user_id, document) DO UPDATE SET user_id = %s, document = %s, progress = %s, percentage = %s, device = %s, device_id = %s, timestamp = %s",
|
|
||||||
(user_id, document, progress, percentage, device, device_id, timestamp, user_id, document, progress, percentage, device, device_id, timestamp))
|
|
||||||
|
|
||||||
pgcon.commit()
|
|
||||||
|
|
||||||
pgcur.close()
|
|
||||||
pgcon.close()
|
|
Loading…
Add table
Add a link
Reference in a new issue