Looking for some advice | Tools & Userscripts | TORN

Looking for some advice

    • PERK_Ryan [3356606]
    • Role: Civilian
    • Level: 44
    • Posts: 734
    • Karma: 164
    • Last Action: 43 minutes
      • 0
    • Reason:
      Are you sure you want to report this post to staff?
      Cancel
    Thread created on 22:00:38 - 16/03/25 (1 month ago)
    |
    Last replied 13:22:21 - 18/03/25 (1 month ago)

    Hey guys, I have some simple knowledge of how to code within python, I made a script to get the data for Faction OC 2.0 results and I can do my own things with that info. This is about the end of my knowledge of writing code. I can manually run it and update the csv I have to always have a storage.

     

    I am now thinking about trying to think of how to have this run a few times a day to try and see who is not making it back to torn in time for the OC.

    I see people Making it for discord bots that seem to be able do what i am attempting, should I look onto that and train myself for that?

     

     I've really learned a lot slogging my way through and I have been enjoying it but I just need guidance.

     

    Thank you for your time

    Ryan's OD Insurance

    • Lewri [1762864]
    • Role: Civilian
    • Level: 98
    • Posts: 1,134
    • Karma: 449
    • Last Action: 7 minutes
      • 1
    • Reason:
      Are you sure you want to report this post to staff?
      Cancel
    Posted on 12:10:46 - 17/03/25 (1 month ago)
    Post link copied to clipboard Copy post link

    Making a discord bot to do this is nice for several reasons: all factions already have discord servers, having it posted on the discord means you don't need to manually share all the results with the parties of interest, you can set up the bot to have other useful utils, and the tasking/scheduling is quite easy.

     

    You could just as well set up some sort of scheduling on your OS to run a script, and then copy paste the outputs, or any number of other solutions, but if you have the time and interest then you might as well look at discord.py.

     

    There's plenty of decent templates out there to get you started, such as https://github.com/egeyardimci/Discord-Py-Bot-Template

    cpomyHC.png

    • Tenren [3373820]
    • Role: Civilian
    • Level: 51
    • Posts: 53
    • Karma: 74
    • Last Action: 15 hours
      • 0
    • Reason:
      Are you sure you want to report this post to staff?
      Cancel
    Posted on 13:42:39 - 17/03/25 (1 month ago)
    Post link copied to clipboard Copy post link

    As mentioned by Lewri, a Discord bot is one option, which would be an application that runs continuously. A slightly simpler option is scheduling a python script to run periodically via something like cron. You can output the data in a variety of ways, from a CSV like you have, Discord channel embeds as a bot or via POST to a webook, updating a Google Sheets document, and more.

     

    Bots/scheduled applications are ideally run on a machine that is usually online 24/7. You can achieve this with cloud-hosted options (like a small VM on GCP, AWS, etc) or self-hosting where something like a Raspberry Pi can come in handy.

    • PERK_Ryan [3356606]
    • Role: Civilian
    • Level: 44
    • Posts: 734
    • Karma: 164
    • Last Action: 43 minutes
      • 0
    • Reason:
      Are you sure you want to report this post to staff?
      Cancel
    Posted on 14:50:53 - 17/03/25 (1 month ago)
    Post link copied to clipboard Copy post link

    I looked at the GCP option and maybe scared myself looking the cost models but I doubt what I'm doing would pass the "free" tier but I didn't even want to attempt that (I'm sure my knowledge is more dangerous right now than helpful haha).

     

    I think I will give discord.py a go and see how it works. It will also help me with getting more used to github as well.

     

    I appreciate your advice

    Ryan's OD Insurance

    • Xradiation [2254540]
    • Role: Civilian
    • Level: 41
    • Posts: 402
    • Karma: 329
    • Last Action: 6 hours
      • 0
    • Reason:
      Are you sure you want to report this post to staff?
      Cancel
    Posted on 19:38:38 - 17/03/25 (1 month ago)
    Post link copied to clipboard Copy post link

    You can use a google sheets document with script attached and then set a time trigger.

    In the script it is as simple as:

    let url = 'https://api.torn.com/faction/?selections=basic&key=YOURAPIKEY';
    var response = UrlFetchApp.fetch(url);
    var responseJSON = JSON.parse(response.getContentText());
    responseJSON.members;

     

    And to add it to the sheet you can do something like

    var sheet = SpreadsheetApp.getActiveSheet();
     
    //sheet.getRange(row, column, optNumRows, optNumColumns);
    var range = sheet.getRange(1, 1);
    range.setValue(SOME_VALUE);
    Last edited by Xradiation on 19:39:00 - 17/03/25 (1 month ago)
    Come to the dark side, we have cookies.
    Welcome, the cookies are a lie
    • PERK_Ryan [3356606]
    • Role: Civilian
    • Level: 44
    • Posts: 734
    • Karma: 164
    • Last Action: 43 minutes
      • 0
    • Reason:
      Are you sure you want to report this post to staff?
      Cancel
    Posted on 22:46:44 - 17/03/25 (1 month ago)
    Post link copied to clipboard Copy post link

    Xradiation [2254540]

    You can use a google sheets document with script attached and then set a time trigger.

    In the script it is as simple as:

    let url = 'https://api.torn.com/faction/?selections=basic&key=YOURAPIKEY';
    var response = UrlFetchApp.fetch(url);
    var responseJSON = JSON.parse(response.getContentText());
    responseJSON.members;

     

    And to add it to the sheet you can do something like

    var sheet = SpreadsheetApp.getActiveSheet();
     
    //sheet.getRange(row, column, optNumRows, optNumColumns);
    var range = sheet.getRange(1, 1);
    range.setValue(SOME_VALUE);

    Does the time trigger even when no one's using the sheet?

    Ryan's OD Insurance

    • Tenren [3373820]
    • Role: Civilian
    • Level: 51
    • Posts: 53
    • Karma: 74
    • Last Action: 15 hours
      • 0
    • Reason:
      Are you sure you want to report this post to staff?
      Cancel
    Posted on 13:22:21 - 18/03/25 (1 month ago)
    Post link copied to clipboard Copy post link

    PERK_Ryan [3356606]

    Does the time trigger even when no one's using the sheet?

    You can set a time trigger to execute a function even if no one is looking at a sheet. 

Reply
Thread Title: