Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Writing character information to file for display in other programs

I'm trying to find a way to obtain character information (such as HP, AC, level) and write it to a file on the machine (such as a text file) so it can be used in OBS.  Ideally it will update the file as needed so the numbers in OBS will update when the player makes changes.  My initial approach was to write a python script and scrape the character sheets for that information but I'm unsure how feasible that is for various reasons.  My second approach is to write a script to run in roll20 itself that will write the character sheet attributes to a file using HTML5's FileSystem API.  I don't usually work in web app land, so was looking for some advice from you all.  If you were to accomplish this task, how would you go about it? Thank you very much for your time.
1555905627
The Aaron
Roll20 Production Team
API Scripter
The Roll20 API doesn’t have access to the FileSystem API. Even if it did, it wouldn’t do you any good. The API runs on a sandbox in the cloud, it doesn’t run in your local browser instance.  My recommendation would be to have the API output the details you want into the chat, probably whispered to some secondary account, then scrape them with a browser extension to write to a file on your local machine. 
1555908449
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
The best way I've seen this done is to make a handout or character, as long as it's accessible via the external journal. Then have your API script output all relevant character info to the notes section of that handout/character. Best bet would be to do it in some sort of formatted dataset. Then have your puthon script monitor the external journal entry. The journal entry will update in real time, so just have your puthon watch for a change and update your obs display at that point 
Ah awesome thank you both for your responses!  They are both tremendously helpful!  I'll see what I can cook up.
1555963514
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
You can take a look at this thread . It's old (and hence locked), and doesn't go into specifics, but it seems to be possible. I used to use a manual updating system, but decided it was far too much work to keep current.
Awesome thank you guys for your input it looks like it's going to be a reality.  Finished the script for Roll20 tonight that outputs health/ac data to a handout in a formatted fashion such that I can scrape it with a python script.  If there's any interest in the Roll20 script I can post it for you!  It'll be easy enough to switch around for your own purposes.
1556101661
The Aaron
Roll20 Production Team
API Scripter
You should post it for future peeps. We could also give you feedback on the code, if you’re interested. 
Alright so I've actually run into a pretty bad snag.&nbsp; I wrote the script and it works beautifully.&nbsp; Unfortunately I need to be logged into Roll20 to view the handout in the external journal.&nbsp; To web scrape it with Python I make a python web session and attempt to log in that way but it never works, and I don't know why.&nbsp; I create a request object and use <a href="https://app.roll20.net/sessions/new" rel="nofollow">https://app.roll20.net/sessions/new</a> &nbsp;as the post destination and use email and password as my payloads for the post.&nbsp; Does anybody have any insight into that?&nbsp; I assume there's some sort of token that needs to be included or saved or something but I cannot figure out what it is or how to do it.&nbsp; I was using&nbsp; <a href="http://kazuar.github.io/scraping-tutorial/" rel="nofollow">http://kazuar.github.io/scraping-tutorial/</a> &nbsp;as a guide.&nbsp; This may be an argument for using a browser extension to scrape the values. At any rate, below is my Roll20 script.&nbsp; It detects changes to character attributes, makes sure that it's a character controlled by a player (it is controlled by more than one person, and yes I know there's more accurate ways of doing it but it was easier to do it this way), and formats and updates the handout's gmnotes with the information.&nbsp; Interestingly I found out that attributes and characters are always fetched in the same order so instead of having to bend over backwards I can always pull apart and re-assemble the formatted string that gets put into the handout and the numbers and where they come from will always be the same. Code:&nbsp; <a href="https://pastebin.com/Csa3sDv5" rel="nofollow">https://pastebin.com/Csa3sDv5</a>
1556190855
The Aaron
Roll20 Production Team
API Scripter
I don't know specifically what you're missing, but I can tell you how I'd look for it. Open an incognito session in chrome. Load the developer tools and turn on preserve logs. Log into Roll20 and look at what gets posted and what cookies get set. I think you just need to provide those cookies along with the request for the handout page. Once you know what the cookie is, you can probably pull it out of the browser with your python script automatically. Youre right that this is why I suggested the browser extension, so you can get the login/access for free. Writing it yourself is a pain.&nbsp;
1556196604
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Alternatively, you could make your make your game public which will allow anyone to view the game's forums and external journal. Which reminds me, that data storage character should be viewable by all players.
1556203761
The Aaron
Roll20 Production Team
API Scripter
(Won't have to be if he gets the login working, but will if he goes the public route)
1556204017
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Sorry, yes. Thanks for clarifying my ramblings Aaron
After much thought and research, the Extension option is likely the easiest, but even extensions can't directly write to a specified file location.&nbsp; Extensions (in Chrome at least) can save the values to a file but it will be in an obfuscated location and file name (which wouldn't be helpful).&nbsp; The way around this is to write the extension and then ALSO a native Chrome app on the computer itself to read Chrome Native Messages from the extension.&nbsp; It seems every approach as a "gotcha".&nbsp; I'm going to try and see if I can find what gets sent/received from Roll20 login to perhaps get a session going in the python script.
@The Aaron In chrome dev tools console I see some GET lines, and under the Application tab I see some cookies.&nbsp; Under Network I see a whole bunch of stuff including some redirects with cookies that have several bits to them (I think these values may be consistent between sessions).&nbsp; Sadly, I don't really know what I'm looking for.&nbsp; Do you have any resources you recommend so I can read up on this, or an explanation?
1556852728
The Aaron
Roll20 Production Team
API Scripter
I don't know, I'd probably start with something like:&nbsp; <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies</a>