Guest User

myFedditUserData

a guest
Jun 22nd, 2024
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Basic login script for Lemmy API
  4.  
  5. # CHANGE THESE VALUES
  6. my_instance="https://feddit.de" # e.g. https://feddit.nl
  7. my_username="" # e.g. freamon
  8. my_password="" # e.g. hunter2
  9.  
  10. ########################################################
  11.  
  12. # Lemmy API version
  13. API="api/v3"
  14.  
  15. ########################################################
  16.  
  17. # Turn off history substitution (avoid errors with ! usage)
  18. set +H
  19.  
  20. ########################################################
  21.  
  22. # Login
  23. login() {
  24. end_point="user/login"
  25. json_data="{\"username_or_email\":\"$my_username\",\"password\":\"$my_password\"}"
  26.  
  27. url="$my_instance/$API/$end_point"
  28.  
  29. curl -H "Content-Type: application/json" -d "$json_data" "$url"
  30. }
  31.  
  32. # Get userdata as JSON
  33. getUserData() {
  34. end_point="user/export_settings"
  35.  
  36. url="$my_instance/$API/$end_point"
  37.  
  38. curl -H "Authorization: Bearer ${JWT}" "$url"
  39. }
  40.  
  41. JWT=$(login | jq -r '.jwt')
  42.  
  43. printf 'JWT Token: %s\n' "$JWT"
  44.  
  45. getUserData | jq > myFedditUserData.json
Advertisement
Add Comment
Please, Sign In to add comment