Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Hadlock
Nov 9, 2004

I have a bunch of immutable game data (specialty fantasy playing card data, like magic) I need to load into my statically compiled game engine

What's the best way to handle this? In python I would just have a card_data.yaml or json file, then serialize that into card objects on start

Adbot
ADBOT LOVES YOU

spiritual bypass
Feb 19, 2008

Grimey Drawer
What's the language and what do you want to accomplish? You could still load from a serialized file at runtime, embed the file in the binary and load from that, or generate a file with all the objects you need statically built.

KillHour
Oct 28, 2007


Yeah, there's nothing about a compiled language that prevents you from doing any kind of data storage technique you could do with a JIT language. I would still do some kind of external serialized file so you don't need to recompile a new build any time you wanted to update or release a card. JSON or XML are pretty standard for that. Also, come visit us in the game design thread!

Hadlock
Nov 9, 2004

cum jabbar posted:

generate a file with all the objects you need statically built.

Ooh, I like this

It's in rust, it's just an ncurses clone of slay the spire (roguelike) to keep my skills from getting too dull

I think I'll just write a file generator like you suggested, and add the ability to import a file on start

foutre
Sep 4, 2011

:toot: RIP ZEEZ :toot:
Not sure if this is the best spot for this, but is there any way to use the parts of the Spotify API that require user authorization without actually loading up a browser with the redirect url at some point?

Basically, I'm trying to make a button that you can just click to save songs on spotify (using the Spotipy library) but the weak little Raspberry Pi Zero W I'm using can't actually load the authorization page in Chromium - it can make calls that don't require authorization just fine though.

Worst case, I could use a different Raspberry Pi - basically, just want a box with a button I can press without having to open my phone.

KillHour
Oct 28, 2007


Instead of using chromium to handle rendering the webpage, can't you just interact with the webserver directly? Take a look at the login page and see how the credentials are submitted. As long as that page doesn't have a captcha or something, Spotify shouldn't care if you're a person or not. If it does have some kind of captcha, you might have to manually auth on one device, capture the access and refresh tokens, and manually store them in your app.

Edit: vv That's a good way to do it

KillHour fucked around with this message at 07:38 on Apr 17, 2022

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆

foutre posted:

Not sure if this is the best spot for this, but is there any way to use the parts of the Spotify API that require user authorization without actually loading up a browser with the redirect url at some point?

Basically, I'm trying to make a button that you can just click to save songs on spotify (using the Spotipy library) but the weak little Raspberry Pi Zero W I'm using can't actually load the authorization page in Chromium - it can make calls that don't require authorization just fine though.

Worst case, I could use a different Raspberry Pi - basically, just want a box with a button I can press without having to open my phone.

Rather than running a web browser on your raspberry pi it seems like you should run a web server (which should be more lightweight). Serve a webpage on your local network that has a "log in through spotify" button and then just visit that page on your phone.

That's the method Spotify shows off on their own web api tutorial page at least.

Their examples are in nodejs w/ Express but you should be able to do basically the same thing in Python with Flask.

RPATDO_LAMD fucked around with this message at 07:38 on Apr 17, 2022

Computer viking
May 30, 2011
Now with less breakage.

Hadlock posted:

Ooh, I like this

It's in rust, it's just an ncurses clone of slay the spire (roguelike) to keep my skills from getting too dull

I think I'll just write a file generator like you suggested, and add the ability to import a file on start

Looking at rust things, you could use serde_json or the binary version to do the same card_data.json idea as in python. You could even have a json file locally and write a small tool that converts it to the binary form, and distribute that one (since it should load faster)?

foutre
Sep 4, 2011

:toot: RIP ZEEZ :toot:

RPATDO_LAMD posted:

Rather than running a web browser on your raspberry pi it seems like you should run a web server (which should be more lightweight). Serve a webpage on your local network that has a "log in through spotify" button and then just visit that page on your phone.

KillHour posted:

Instead of using chromium to handle rendering the webpage, can't you just interact with the webserver directly? Take a look at the login page and see how the credentials are submitted. As long as that page doesn't have a captcha or something, Spotify shouldn't care if you're a person or not. If it does have some kind of captcha, you might have to manually auth on one device, capture the access and refresh tokens, and manually store them in your app.



Oh yup, thank you! This seems much lighter weight than the Spotipy/chromium version. I figured there had to be a better way but I kept looking at the Spotipy docs instead of Spotify API, whoops. I've done some stuff with Express in the past so hopefully can figure it out w/o too much trouble.

dirby
Sep 21, 2004


Helping goons with math

KillHour posted:

Edit: It really looks like the blue and white (both tangents negative or both tangents positive) are always wrong and the cyan and magenta (one tangent negative and one positive) are correct.


I know this is very late, and I haven't combed through the details, but I wonder if you ended up reinventing atan2, which probably already exists in your language.

worms butthole guy
Jan 29, 2021

by Fluffdaddy
I think this belongs in here...


A few years ago a Goon I believe did a blog post about creating software that allows courts to have a version of their floorplans accesable to users, sort of like a touchscreen kiosk. Does anyone remember the Goon / what the software was called?

I could be imagining this.

Thanks

Gothmog1065
May 14, 2009
I'm having a dumb, and google isn't giving me a good answer. This is in shell, KSH 93 mainly.

Simply put, I'm collecting a list of words from directory filenames into a variable, then I want to unique sort that list to do other stuff. In essence:

code:
list="a\nb\nq\nd\nf\na\nc\na"

sortList=$(echo $list | sort -u)
printf $sortLIst


Doesn't work, it just prints the unsorted list out.

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆

Gothmog1065 posted:

I'm having a dumb, and google isn't giving me a good answer. This is in shell, KSH 93 mainly.

Simply put, I'm collecting a list of words from directory filenames into a variable, then I want to unique sort that list to do other stuff. In essence:

code:
list="a\nb\nq\nd\nf\na\nc\na"

sortList=$(echo $list | sort -u)
printf $sortLIst


Doesn't work, it just prints the unsorted list out.

Echo does not interpret escape sequences like \n, so it's outputting the literal characters '\' and 'n' rather than the whitespace sort wants.

It seems like
code:
sortList=$(printf "$list" | sort -u)
should do what you want.

RPATDO_LAMD fucked around with this message at 22:09 on Apr 27, 2022

Gothmog1065
May 14, 2009
That and the quotes I kept forgetting to add. Thank you!

Azuth0667
Sep 20, 2011

By the word of Zoroaster, no business decision is poor when it involves Ahura Mazda.
Is there a function I can use in C or python that would let me read text from a program in one window then input a text command depending upon what the text was?

KillHour
Oct 28, 2007


As in try to find where in memory that text is stored and read it or grab the screen pixels and try to OCR them?

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆
Yeah uh this sounds like the typical X-Y problem where you have one thing you're trying to do, you've decided OCRing the screen from C is somehow the best solution, and now you're asking about how to do ocr in C instead of asking about your actual end goal.

I'd suggest looking into autohotkey if you're trying to mess around with graphical windows programs somehow but really I have no idea what you're trying to do.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Azuth0667 posted:

Is there a function I can use in C or python that would let me read text from a program in one window then input a text command depending upon what the text was?

If you want to automate your wrong voting just say that, no need to beat around the bush.

Azuth0667
Sep 20, 2011

By the word of Zoroaster, no business decision is poor when it involves Ahura Mazda.
^^: I would love for it to be something fun like that. This is drudgery that we could resolve if we were willing to update 70s era instruments but the budget people are gaping assholes so that will never happen.

KillHour posted:

As in try to find where in memory that text is stored and read it or grab the screen pixels and try to OCR them?

I'm a novice at best so I am not sure which approach is best. Its a proprietary application that has a window with two boxes one shows text and the other is for the input of commands. The text is either it updating the progress of the program, some action the program is taking or the result of the action. The text is usually less than a page but most of what it displays is not useful for decision making.

I've only got a few commands I'd use for it so I'd like to automate my responses and let it run over night.

Super-NintendoUser
Jan 16, 2004

COWABUNGERDER COMPADRES
Soiled Meat

Azuth0667 posted:

^^: I would love for it to be something fun like that. This is drudgery that we could resolve if we were willing to update 70s era instruments but the budget people are gaping assholes so that will never happen.

I'm a novice at best so I am not sure which approach is best. Its a proprietary application that has a window with two boxes one shows text and the other is for the input of commands. The text is either it updating the progress of the program, some action the program is taking or the result of the action. The text is usually less than a page but most of what it displays is not useful for decision making.

I've only got a few commands I'd use for it so I'd like to automate my responses and let it run over night.

Pyautogui is super neat:

https://pyautogui.readthedocs.io/en/latest/

It basically is a module that allows you to screenshot whatever, process it, do OCR, picture matching, and then also it has the ability to enter keyboard or mouse commands as needed. I used it back in the day to write a frame work that would look at screenshots of Android phones and autoclick through apps to get points in games or giftcards. It works really well. It's a pretty simple python module as well, so it's a nine babies first step into an actual python application.

There's another product, memory escapes me, but it basically is a headless Chromium browser that exposes webpages as static PNG images. These two tools together are super powerful to web scrape and act on the output.

Embarrassingly, we used to have a sales exec that wanted a specific page from JIRA sent to him every day, but it required a little bit of data entry, so one of our guys (he's a goon that watches this thread, maybe he'll answer) wrote a little app with those two libraries that browsed to JIRA, made the search he wanted, screenshotted and emailed the result.

It was a really poor idea, but it worked for him.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Azuth0667 posted:

^^: I would love for it to be something fun like that. This is drudgery that we could resolve if we were willing to update 70s era instruments but the budget people are gaping assholes so that will never happen.

I'm a novice at best so I am not sure which approach is best. Its a proprietary application that has a window with two boxes one shows text and the other is for the input of commands. The text is either it updating the progress of the program, some action the program is taking or the result of the action. The text is usually less than a page but most of what it displays is not useful for decision making.

I've only got a few commands I'd use for it so I'd like to automate my responses and let it run over night.

Seconding AutoHotkey, this sounds like a perfect use.

Insurrectionist
May 21, 2007
I have a small deployment question about Docker. Running a program which uses a python library that takes a file and splits the file into two separate files. This library is being run through an os.system command and spits out a few annoying and uninteresting versioning warnings during this process, so while coding the program these warnings were pipelined to dev/null with no issue.

When trying to set this up with Docker, this then creates a problem where the program, on hitting this line, does not wait for the library to finish splitting the file. Since the very next line of code is using one of the two resulting files - that does not yet exist - this gives us a big ol stinking error. If the pipeline is removed, everything waits politely as it does locally but with the disgusting warning text once again cluttering the screen.

I don't know that much about VM but I understand it's a quirk of containerized machines. Is setting up a subprocess solution the best way to deal with this, or is there an easier/cleaner solution?

spiritual bypass
Feb 19, 2008

Grimey Drawer
I'm trying to help someone with a legitimate business who's adopted a pay-what-you-want model. After a couple weeks of accepting payments via Paypal donate button, their account was frozen and Paypal's customer care team has been predictably terrible.

Can anyone recommend payment processors that allow pay-what-you-want, ideally as a no-code hosted form? It seems possible to code up something with Stripe or Square, but I'd rather deliver something generic today instead of something custom next week since revenue has come to a standstill.

e: Square's "hosted checkout link" feature ought to do the trick

spiritual bypass fucked around with this message at 19:28 on May 3, 2022

KillHour
Oct 28, 2007


cum jabbar posted:

I'm trying to help someone with a legitimate business who's adopted a pay-what-you-want model. After a couple weeks of accepting payments via Paypal donate button, their account was frozen and Paypal's customer care team has been predictably terrible.

Can anyone recommend payment processors that allow pay-what-you-want, ideally as a no-code hosted form? It seems possible to code up something with Stripe or Square, but I'd rather deliver something generic today instead of something custom next week since revenue has come to a standstill.

e: Square's "hosted checkout link" feature ought to do the trick

Places like Itch and HumbeBundle are probably the closest to what you want, since they were built with that model in mind. I know his business probably isn't a video game but I'd start there.

nelson
Apr 12, 2009
College Slice

cum jabbar posted:

I'm trying to help someone with a legitimate business who's adopted a pay-what-you-want model. After a couple weeks of accepting payments via Paypal donate button, their account was frozen and Paypal's customer care team has been predictably terrible.

Can anyone recommend payment processors that allow pay-what-you-want, ideally as a no-code hosted form? It seems possible to code up something with Stripe or Square, but I'd rather deliver something generic today instead of something custom next week since revenue has come to a standstill.

e: Square's "hosted checkout link" feature ought to do the trick

It’s not really a donation right? Couldn’t the customer enter what they want then be processed normally (i.e. not donation) through paypal for that amount?

spiritual bypass
Feb 19, 2008

Grimey Drawer
"Donation" is a red herring here. It's a Paypal payment link. Any further money given to Paypal is potentially going to end up being stolen by Paypal at this point since the account has been frozen for nearly a week.

skooma512
Feb 8, 2012

You couldn't grok my race car, but you dug the roadside blur.
I frequently need to delete Windows profiles that build up overtime and clog up drives.

Doing this manually is time consuming since a profile is thousands of little files and Windows chugs when you try to make it do that, especially when you do it dozens of time over.

Anybody got a Powershell script lying around that could do this? I've heard that using anything other than File Explorer to delete is faster, is that true?

Hadlock
Nov 9, 2004

I would learn how to write this yourself and double your value to the company then go ask for a raise

You're asking the right questions, I could write this script for you in 5 minutes but I think there's a lot of value in doing it yourself

If it's faster? I dunno. PowerShell is going to call the same filesystem API as explorer. It's not going to get distracted and wander off half way through though. It may be 5% faster? This is a good exercise though

KillHour
Oct 28, 2007


Just don't do what I did when I first started learning how to automate stuff and run the script without testing on my company's production network. You don't want to accidentally delete everyone's windows account...

Hadlock
Nov 9, 2004

Oh yeah, test locally, show it to your boss and be like "hey this worked, we're going to do this from now on"

PowerShell has changed a lot in the last 8 years but I think there's some hoops you need to jump through to damage other networked computers, unless your user just has full super admin, which is entirely possible. Beware thar be dargons

skooma512
Feb 8, 2012

You couldn't grok my race car, but you dug the roadside blur.

Hadlock posted:

I would learn how to write this yourself and double your value to the company then go ask for a raise

You're asking the right questions, I could write this script for you in 5 minutes but I think there's a lot of value in doing it yourself

If it's faster? I dunno. PowerShell is going to call the same filesystem API as explorer. It's not going to get distracted and wander off half way through though. It may be 5% faster? This is a good exercise though

This is true, and yea I managed to figure out the process of filtering based on lastwritetime well enough.

Now it's saying I don't have the permissions to delete anything, even though I launched as admin. -Credentials is specifically not allowed for remove-item. The error is a loving red herring talking about PSdrives, which seem to just be a way to alias and that didn't help either. Now I'm reading I have to take ownership of all the profiles first, which makes a job that takes one line of code into a monstrosity.

nielsm
Jun 1, 2009



skooma512 posted:

I frequently need to delete Windows profiles that build up overtime and clog up drives.

Doing this manually is time consuming since a profile is thousands of little files and Windows chugs when you try to make it do that, especially when you do it dozens of time over.

Anybody got a Powershell script lying around that could do this? I've heard that using anything other than File Explorer to delete is faster, is that true?

Use the WMI interface for it.

code:
$allProfiles = Get-WmiObject -Class Win32_UserProfile
# select the profiles you need to delete here
$profile | Remove-WmiObject
If you need to figure out who owns each profile, the best bet is to look it up based on the SID property of the Win32_UserProfile object. You can search for the SID in Active Directory, or use a different API to map it to a local user.
You can use the Special and Loaded properties to filter out special system profiles, and determine which ones are loaded/logged in right now.
Beware that the LastUseTime property is generally not reliable, if you want to know when it was last used you're better off looking at the modification date of the file system folder for the profile (the LocalPath property).

Gothmog1065
May 14, 2009
So wanted to kind of bounce an idea to make sure I'm not going down a path this not completely wrong.

I'm looking to compare two folders to see what is different between the two folders. The basic call is going to be as follows (KSH 93):

code:
compare () {
     
  curFileList=$(find ${curPath}/${1} -maxdepth 1 -type f)
  compFileList=$(find ${compPath}/${1} -maxdepth 1 -type f)

}

prog_run () {

  get_env_and_site
  init_args $@

  curPath="${HCIROOT}/${curFull}/"
  compPath="${HCIROOT}/${compFulls}/"
  compList="Tables xlate tclprocs NetConfig"

 
  for dir in $compList; do
    printf "Curently comparing the ${dir} for ${curSite} and ${compSite}..."
    compare ${dir}

  done

}
The plan is to loop over the lists, check to see if the file exists in the opposite directory, then compare the files themselves (file1=$(${path}/file); file2=$(${path}/file) then if [[ ${file1} != ${file2} ]]; echo messages), echoing out the differences if there are any. I know it's a small snippit of code, but any suggestions are welcome.

nielsm
Jun 1, 2009



I think maybe rsync can do it for you, if you ask it to do a dry run and print what it wants to do.

Otherwise, merge the lists to a single and compare that to each of the sides. That makes it the easiest to figure out extra and missing files.
Of course, all lists should be sorted.

ExcessBLarg!
Sep 1, 2001

Gothmog1065 posted:

The plan is to loop over the lists, check to see if the file exists in the opposite directory, then compare the files themselves (file1=$(${path}/file); file2=$(${path}/file) then if [[ ${file1} != ${file2} ]]; echo messages), echoing out the differences if there are any. I know it's a small snippit of code, but any suggestions are welcome.
Some thoughts here:

1. If you want to generate a list of files that aren't the same between the two directories (and why, whether they only exist in 1, in 2, or if there's deltas) you can abuse rsync(1) to generate that list for you:
code:
rsync -ricn --delete "$1/" "$2"
The output is a bit cryptic, though explained in the man page. This will tell you if the file exists in 1 and needs to be copied to 2, if it exists in both but there's checksum differences, or if the file doesn't exist in 1 and does in 2. This may make it easier for your script to go through the list once and apply the appropriate messaging in each situation.

2. You can also do a 'diff -rU0 "$1" "$2"' to give you a list of differences although with a different format, and not one file per line.

3. If you prefer to do the comparisons manually on each file with cmp, you can iterate over each list but if there's a lot of files in common between the two you'll be performing the comparisons twice. To make that more efficient you want to generate a difference set of the files in the second directory and the first and then iterate over that difference set for the second loop.

Gothmog1065
May 14, 2009
Thank you both. I'll definitely look into rsync. I don't expect there to be a glut of files in each directory, I'm talking small <50 files. I'm not really looking to see what the difference are, just that there are differences. While you guys replied, I slapped this (VERY UNTESTED, likely to be some very stupid mistakes) together:

code:
compare () {

  if [[ $1 == "netconfig" ]]; then
    printf "NetConfig to come later"
    continue
  else
    compList=""
    printf "\nChecking for missing files:"
    check_dir cur $1
    check_dir comp $1

    printf "\n\nComparing files between %s and %s\n" ${curFull} ${compFull}

    [[ "${compList}" != "" ]] && compare_files

  fi

}

check_dir () {

  if [[ "$1" == "cur" ]]; then
    dir1="${curPath}/$1/"
    dir2="${compPath}/$1/"
  else
    dir1="${compPath}/$1/"
    dir2="${curPath}/$1/"
  fi

  fileList=$(find ${dir1} -maxdepth 1 -type f | sort)

  for file in ${fileList1}; do
    if [[ -f ${dir2}/${file##/*} ]]; then
      compList="${file##/*} "
    else
      printf "%s is not found in %s" ${file##/*} ${dir2}
    fi

  done

}

compare_files () {

  for file in ${compList}; do
    curFile=$(${curPath}/${file##/*})
    compFile=$(${compPath}/${file##/*})
    if [[ "${curFile}" == "${compFile}" ]]; then
      (( ${quiet} == 0 )) && printf "%s/%s is the same" ${location} ${file##/*}
    else
      printf "%s/%s is different" ${location} ${file##/*}
    fi

  done

}

prog_run () {

  get_env_and_site
  init_args $@

  curPath="${HCIROOT}/${curFull}/"
  compPath="${HCIROOT}/${compFulls}/"
  compList="Tables xlate tclprocs NetConfig"

 
  for location in $compList; do
    printf "Currently comparing the ${location} for ${curSite} and ${compSite}..."
    compare ${location}

  done

}
And another unrelated question. I don't do a lot of text formatting for the most part, is there a general preference between printf using %s and just calling the variable inside the quotes?

code:
 printf "%s/%s is the same" ${dir} ${file##/*}
vs
code:
printf "${dir}/${file##/*} is the same"

Gothmog1065 fucked around with this message at 15:25 on May 6, 2022

ExcessBLarg!
Sep 1, 2001

Gothmog1065 posted:

While you guys replied, I slapped this (VERY UNTESTED, likely to be some very stupid mistakes) together:
So, when you say you want to "compare the files themselves", you mean you want to figure out if there's differences in the contents of the file, right? The '"${curFile}" == "${compFile}"' comparison just determines if the two strings are the same (which they would be since you've just constructed them as such). To actually compare the files you'll need to use cmp(1).

I didn't evaluate the script too closely, but the one thing I did catch was the use of "continue" in compare(). I'm not sure off hand if that actually works, but even if it does I wouldn't use continue statements far away from the loop.

Gothmog1065 posted:

And another unrelated question. I don't do a lot of text formatting for the most part, is there a general preference between printf using %s and just calling the variable inside the quotes?
Just use "echo" with string interpolation. I'd only use printf if you need to use the % formatters. It also has the annoying property of not automatically terminating with newlines, so if you're running this on a line-buffered terminal you won't see your output right away.

Gothmog1065
May 14, 2009

ExcessBLarg! posted:

So, when you say you want to "compare the files themselves", you mean you want to figure out if there's differences in the contents of the file, right? The '"${curFile}" == "${compFile}"' comparison just determines if the two strings are the same (which they would be since you've just constructed them as such). To actually compare the files you'll need to use cmp(1).

I didn't evaluate the script too closely, but the one thing I did catch was the use of "continue" in compare(). I'm not sure off hand if that actually works, but even if it does I wouldn't use continue statements far away from the loop.

Just use "echo" with string interpolation. I'd only use printf if you need to use the % formatters. It also has the annoying property of not automatically terminating with newlines, so if you're running this on a line-buffered terminal you won't see your output right away.

Thanks again! The continue was one of the 'stupid' mistakes I've already fixed. I've been adding \n's in the printf, but if echoes are more typically used in these scenarios, not difficult to switch.

Hadlock
Nov 9, 2004

Gothmog1065 posted:

And another unrelated question. I don't do a lot of text formatting for the most part, is there a general preference between printf using %s and just calling the variable inside the quotes?

The correct solution is just write code that doesn't need text formatting. elseif: printf "WARN: The two items are the same" is enough information in most cases

Adbot
ADBOT LOVES YOU

necrotic
Aug 2, 2005
I owe my brother big time for this!

Hadlock posted:

The correct solution is just write code that doesn't need text formatting. elseif: printf "WARN: The two items are the same" is enough information in most cases

Which two out of these 1000 things, or even just 5 things? No context in output frustrates the hell out of me.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply