Steal innocent emojis and add them to your pleroma instance.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

58 行
2.0KB

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