Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jakimfett/701ce197e9fbb65e33d8fae9227d04eb to your computer and use it in GitHub Desktop.
Save jakimfett/701ce197e9fbb65e33d8fae9227d04eb to your computer and use it in GitHub Desktop.
#!/bin/bash
# This stupid script can convert slack json exports
# (created with https://solawivuml.slack.com/apps/A19P6G35Y-export?next_id=0)
# to rocket.chat csv imports.
# The zip file can be directelly imported into rocket.chat.
test -z $1 && echo "usage: $0 slack_export_json_file.json channel_name" && exit 1
# format users (needed for import)
cat $1 | jq '.[] | {name,real_name} | @json' | awk -F '"' '{print $5","$5"@dummy.import,"$9}' | sed 's#\\##g' | sort -n | uniq >users.csv
# format channel messages
mkdir -p $2
cat $1|jq '.[] | {name,ts,text} | map(.) | @csv' | sed 's#\"\\\"#"#g'|sed 's#\\\",\\\"#","#g' | sed 's#\\\"\"#"#g' | sed "s#\\\\\"#'#g" >$2/messages.csv
grep -v '^",' $2/messages.csv >$2/messages.csv2
# cleanup ts digit
sed -i 's#\.[[:digit:]]\+##g' $2/messages.csv2
# multiply ts to miliseconds
awk -F'","' '{print $1"\",\""$2*1000"\",\""$3}' $2/messages.csv2 >$2/messages.csv
rm $2/messages.csv2
# add newlines again
sed -i "s#\\\n#\n#g" $2/messages.csv
# create zip file
zip -ru channel_$2.zip channels.csv users.csv $2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment