diff options
author | Mark Haines <mjark@negativecurvature.net> | 2015-05-06 12:54:07 +0100 |
---|---|---|
committer | Mark Haines <mjark@negativecurvature.net> | 2015-05-06 12:54:07 +0100 |
commit | 3c11c9c122ec73c495bd691ba8608ad6a406b332 (patch) | |
tree | 8c9b339ce336b8d1dd45a3ac899c1875612236aa /scripts-dev/make_identicons.pl | |
parent | Merge pull request #138 from matrix-org/erikj/SYN-371 (diff) | |
parent | Acutally add scripts-dev/ (diff) | |
download | synapse-3c11c9c122ec73c495bd691ba8608ad6a406b332.tar.xz |
Merge pull request #140 from matrix-org/erikj/scripts_refactor
Seperate scripts/ into scripts/ and scripts-dev/
Diffstat (limited to 'scripts-dev/make_identicons.pl')
-rwxr-xr-x | scripts-dev/make_identicons.pl | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/scripts-dev/make_identicons.pl b/scripts-dev/make_identicons.pl new file mode 100755 index 0000000000..cbff63e298 --- /dev/null +++ b/scripts-dev/make_identicons.pl @@ -0,0 +1,39 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use DBI; +use DBD::SQLite; +use JSON; +use Getopt::Long; + +my $db; # = "homeserver.db"; +my $server = "http://localhost:8008"; +my $size = 320; + +GetOptions("db|d=s", \$db, + "server|s=s", \$server, + "width|w=i", \$size) or usage(); + +usage() unless $db; + +my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","") || die $DBI::errstr; + +my $res = $dbh->selectall_arrayref("select token, name from access_tokens, users where access_tokens.user_id = users.id group by user_id") || die $DBI::errstr; + +foreach (@$res) { + my ($token, $mxid) = ($_->[0], $_->[1]); + my ($user_id) = ($mxid =~ m/@(.*):/); + my ($url) = $dbh->selectrow_array("select avatar_url from profiles where user_id=?", undef, $user_id); + if (!$url || $url =~ /#auto$/) { + `curl -s -o tmp.png "$server/_matrix/media/v1/identicon?name=${mxid}&width=$size&height=$size"`; + my $json = `curl -s -X POST -H "Content-Type: image/png" -T "tmp.png" $server/_matrix/media/v1/upload?access_token=$token`; + my $content_uri = from_json($json)->{content_uri}; + `curl -X PUT -H "Content-Type: application/json" --data '{ "avatar_url": "${content_uri}#auto"}' $server/_matrix/client/api/v1/profile/${mxid}/avatar_url?access_token=$token`; + } +} + +sub usage { + die "usage: ./make-identicons.pl\n\t-d database [e.g. homeserver.db]\n\t-s homeserver (default: http://localhost:8008)\n\t-w identicon size in pixels (default 320)"; +} \ No newline at end of file |