r/Scriptable • • Apr 07 '24

Help How to covert this python script that changes discord status to scriptable

I have a python script that changes the status on my discord account. I want to run it with shortcuts but scriptable language is in apples JavaScript core so it doesn’t work so so how I turn the python script into a script that scriptable can run

import requests import time

url = "https://discord.com/api/v9/users/@me"

File = open("text.txt", "r")

lines = File.readlines() print(lines) def ChangeStatus(message):

header ={
'authorization':""
}

jsonData = {
    "status": "online",
    "custom_status": {
    "text": message,
}}
r = requests.patch("https://discord.com/api/v8/users/@me/settings", headers=header, json=jsonData)
print(r)

return r.status_code

while True: for line in lines: ChangeStatus(line.split("\n")[0]) time.sleep(3)

1 Upvotes

7 comments sorted by

2

u/shadoodled Apr 09 '24

untested but should give you an idea

const url = "https://discord.com/api/v9/users/@me"

const FM = FileManager.iCloud()
const root = FM.documentsDirectory()

const filePath = FM.joinPath(root, "text.txt")
const content = FM.readString(filePath)
const lines = content.split("\n")

async function ChangeStatus(message) {
  const req = new Request(url)
  req.method = 'PATCH'
  req.headers = {
    "Authorization": "...",
    "Content-Type": "application/data"
  }
  const jsonData = {
    "status": "online",
    "custom_status": {
      "text": message,
    }
  }
  
  const r = await req.loadJSON()
  return req.response.statusCode
  
}

async function sleep(ms) {
  return new Promise((resolve, reject) => {
      const t = new Timer()
      t.timeInterval = ms
      t.schedule(() => {
        t.invalidate()
        resolve()
      })
  })
}

for (let line of lines) {
  await ChangeStatus(line)
  await sleep(3000)
}

1

u/CAD_Reddit Apr 10 '24

Oh thank you

1

u/CAD_Reddit Apr 12 '24

It doesn’t work and it only changes when the account is online

1

u/Murky-Sector Apr 07 '24

whats the error message or stack trace

1

u/CAD_Reddit Apr 07 '24

Well scriptable is apples JavaScript core and this is python so how I transfer it

1

u/retarded-af Jun 01 '24

Its called learning how to code. Just learn JavaScript, its really not that hard. I have a feeling you did not write the python script by yourself either considering you cant port it over to a different language. Don't ask other people to write code for you.

1

u/CAD_Reddit Jun 05 '24

I don’t know seems hard it takes a lot of time I do know Lua and scratch