summaryrefslogtreecommitdiff
path: root/scripts/fill.image_urls.py
diff options
context:
space:
mode:
authortim b <timb@camcompu.home>2010-09-22 10:07:40 -0700
committertim b <timb@camcompu.home>2010-09-22 10:07:40 -0700
commitb5926d12d5a1db933b74d08a2127d8a773bdc5a1 (patch)
tree9d9e4f731abc29485af4d6e17816fa339f554f4b /scripts/fill.image_urls.py
parent8d477e62a32f8e8de21341aca7d3b01a5c2bf118 (diff)
parent42f0d73ba8ed7a2b647cb1cf8dc4ceafcc71a114 (diff)
Merge branch 'master' of ssh://dump.fm/pichat/repo
Diffstat (limited to 'scripts/fill.image_urls.py')
-rw-r--r--scripts/fill.image_urls.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/scripts/fill.image_urls.py b/scripts/fill.image_urls.py
index 0b1c2e3..952b7ea 100644
--- a/scripts/fill.image_urls.py
+++ b/scripts/fill.image_urls.py
@@ -5,20 +5,25 @@ import postgresql
from urllib.parse import urlparse
db = postgresql.open("pq://postgres:root@localhost/dumpfm")
+db.execute("SET CLIENT_ENCODING to 'UNICODE'")
def get_num_images_in_db():
ps = db.prepare("SELECT COUNT(*) FROM image_urls")
return int(ps()[0][0])
def add_url(url):
- print(url)
+ try:
+ print(url)
+ except UnicodeEncodeError:
+ print("i thought python 3 fixed the unicode shit. yet i still get unicode errors everywhere. GOOD JOB FUCKHEADS")
ps = db.prepare("DELETE FROM image_urls WHERE url=$1")
ps(url)
ps2 = db.prepare("INSERT INTO image_urls(url) VALUES($1)")
ps2(url)
+# NOTE. hardcoded room numbers to index here... only indexing DUMPFM (1) and GIF (8) currently.
def get_messages(lower, upper):
- ps = db.prepare("SELECT content FROM messages WHERE message_id >= $1 AND message_id <= $2 ORDER BY message_id ASC")
+ ps = db.prepare("SELECT content FROM messages WHERE message_id >= $1 AND message_id <= $2 AND room_id IN (1,8) ORDER BY message_id ASC")
rows = ps(lower, upper)
return rows
@@ -60,4 +65,4 @@ if __name__ == "__main__":
print("added ", len(urls), " images to db")
num_new_images = get_num_images_in_db() - num_existing_images
percent_new_images = num_new_images / len(urls) * 100
- print(num_new_images, " were new (", percent_new_images ,"%)") \ No newline at end of file
+ print(num_new_images, " were new (", percent_new_images ,"%)")