Steal innocent emojis and add them to your pleroma instance.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

59 Zeilen
2.0KB

  1. #!/usr/bin/env python3
  2. import os
  3. import sys
  4. import json
  5. from urllib.request import Request, urlopen
  6. from urllib.request import urlretrieve
  7. import subprocess
  8. def read_api(api_url):
  9. req = Request(api_url, headers={"User-Agent": 'Mozilla/5.0'})
  10. data = json.loads(urlopen(req).read().decode())
  11. return data
  12. def download_emojis(json):
  13. print("The script will automatically append them to an emoji.txt file if you ever want to add them to your pleroma instance.")
  14. #happy, /emoji/
  15. all_files = []
  16. emoji_file= open("emoji.txt","a")
  17. for emoji in json:
  18. file_extension = emoji["static_url"].split("/")
  19. file_extension = file_extension[-1].split("?")
  20. file_extension = file_extension[0].split(".")
  21. print("Downloading: " + emoji["shortcode"] + "." + file_extension[1])
  22. urlretrieve (emoji["static_url"], "./" + emoji["shortcode"] + "." + file_extension[1])
  23. emoji_file.write(emoji["shortcode"] + ", /emoji/" + emoji["shortcode"] + "." + file_extension[1] + "\n")
  24. all_files.append(emoji["shortcode"] + "." + file_extension[1])
  25. emoji_file.close()
  26. answer = input("Do you want me to move them to the right directory for you?(y/n)")
  27. if answer == "y":
  28. print("I'm assuming pleroma is in /home/pleroma/pleroma as the tutorial suggests.")
  29. if os.path.isdir("/home/pleroma/pleroma/priv/static/emoji"):
  30. for f in all_files:
  31. os.rename(f, "/home/pleroma/pleroma/priv/static/emoji/" + f)
  32. else:
  33. print("Directory doesn't exist, exiting...")
  34. exit(0)
  35. else:
  36. print("Ok, I'm done here,goodbye!")
  37. exit(0)
  38. def treat_url(instance_url):
  39. api_url = instance_url + "/api/v1/custom_emojis"
  40. return api_url
  41. def main():
  42. instance_url = None
  43. try:
  44. instance_url = sys.argv[1]
  45. except IndexError:
  46. print("You need to specify a url.")
  47. exit(0)
  48. api_url = treat_url(instance_url)
  49. api_data = read_api(api_url)
  50. download_emojis(api_data)
  51. main()