This is a quick scraper I threw together for Meatspaces Chat. The database is likely the least efficient way of doing it, but that's what pull requests are for. You need python-mysqldb
(in the debian repos under that name, here's the official page) and socketIO-client
(install with pip/easy_install: sudo pip install socketIO-client
). Fill in the save path to the place you want the images saved and the database credentials.
Last active
November 21, 2021 21:13
-
-
Save thefinn93/7239532 to your computer and use it in GitHub Desktop.
This is a simple scraper for https://chat.meatspac.es
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE IF NOT EXISTS `chats` ( | |
`key` varchar(36) NOT NULL, | |
`fingerprint` varchar(32) NOT NULL, | |
`message` varchar(500) NOT NULL, | |
`ttl` int(11) NOT NULL, | |
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
PRIMARY KEY (`key`) | |
) ENGINE=InnoDB DEFAULT CHARSET=latin1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from socketIO_client import SocketIO # sudo pip install socketIO-client | |
import MySQLdb | |
import base64 | |
savepath = "/var/www/meatspaces/images" | |
db = MySQLdb.connect(user="meatspaceschat", passwd="hax", db="meatspaceschat") | |
def on_message(*args): | |
try: | |
a = open("%s/%s.gif" % (savepath, args[0]['chat']['key']), "w") | |
a.write(base64.b64decode(args[0]['chat']['value']['media'].split(",")[-1])) | |
a.close() | |
print "%s\t%s" % (args[0]['chat']['key'], args[0]['chat']['value']['message']) | |
toinsert = (args[0]['chat']['key'], args[0]['chat']['value']['fingerprint'], args[0]['chat']['value']['message'], args[0]['chat']['value']['ttl'], args[0]['chat']['value']['created']) | |
c = db.cursor() | |
c.execute("INSERT INTO `meatspaceschat`.`chats` (`key`, `fingerprint`, `message`, `ttl`, `created`) VALUES (%s, %s, %s, %s, FROM_UNIXTIME(%s));", toinsert) | |
c.close() | |
db.commit() | |
except: | |
pass | |
socketIO = SocketIO('chat.meatspac.es', 443, secure=True) | |
socketIO.on('message', on_message) | |
socketIO.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment