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
CarForumPoster
Jun 26, 2013

⚡POWER⚡
Imagine being rude to someone who makes a free thing you find useful

Adbot
ADBOT LOVES YOU

Dominoes
Sep 20, 2007

Work on your fork and move on. Don't expect the maintainer to merge your stuff. Don't get emotional about it.

You had an issue with the lib someone wrote, and made publicly available. You fixed it. Open source is working as intended.

Ranzear
Jul 25, 2013

CarForumPoster posted:

Imagine being rude to someone who makes a free thing you find useful

It was and is fundamentally broken, like 'unable to update the position of a model from any code outside the rendering callback' broken. That's like ... a thing you do in game engines, right?

Toast Museum
Dec 3, 2005

30% Iron Chef

rjmccall posted:

If you don’t want to work with people, go off and be a lone genius already and stop pretending you’re contributing to their projects.

Macichne Leainig
Jul 26, 2012

by VG

Ranzear posted:

It was and is fundamentally broken, like 'unable to update the position of a model from any code outside the rendering callback' broken. That's like ... a thing you do in game engines, right?

Without being an rear end in a top hat to OSS contributors, sure.

Dominoes
Sep 20, 2007

Ranzear posted:

It was and is fundamentally broken, like 'unable to update the position of a model from any code outside the rendering callback' broken. That's like ... a thing you do in game engines, right?
You are missing the point.

credburn
Jun 22, 2016
A tangled skein of bad opinions, the hottest takes, and the the world's most misinformed nonsense. Do not engage with me, it's useless, and better yet, put me on ignore.
Hey gang!

In my Introduction to Python course I'm going over exception handling, and I'm writing a small game using PyCharm alongside my studies. I wrote a few ValueError exceptions to out-of-range integer inputs, but when I ran it in PyCharm, it just ignored it and returned "none". So I copied and pasted the code into https://replit.com/languages/python3 and the exception handling works as intended.

I can post the code if you need it, but it's messy and has a lot of other problems going on with it, but my main concern is... why would PyCharm not see it, but Replit does? Is this a common thing, is this something obvious, or... I'm just not sure how I'm supposed to approach this obstacle ha.

Edit: Found out what the problem was. Uhhh PyCharm was running an earlier version of the program? Well, I feel like I'm stumbling around blind but I guess I'm happy to learn I'm misunderstanding how the client works and not the language.

credburn fucked around with this message at 00:10 on Dec 22, 2021

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Ranzear posted:

It was and is fundamentally broken, like 'unable to update the position of a model from any code outside the rendering callback' broken. That's like ... a thing you do in game engines, right?

You're confusing being correct on the merits of your technical argument with being entitled to demand the time and attention of the project maintainer. You can be one of those things without the other.

Lord Lambeth
Dec 7, 2011


Odd question perhaps but I was looking to make a website that has the same structure as http://cachemonet.com

I am someone who has very minimal coding experience but the basics of it do not seem very complex.

boofhead
Feb 18, 2021

That's actually web 4.0, it's not cleared for public use yet

Delete it from your history and move to a non extradition country

KillHour
Oct 28, 2007


Are you asking how it works? Because it's most likely a bunch of gifs with the URLs of those gifs stored in two JS arrays and a timer to swap them out.

Edit: That's exactly what it is.

code:
var gif_bgs 	= [];
var gif_center 	= [];

var length_bgs = 0;
var length_center = 0;

var timer;
var duration = 4000;
var loaded = 0;
var next_bg;
var next_center;
var audio = document.getElementById("sound");
var muted = false;

function next(e){	
	clearInterval(timer);
	timer = setInterval(next, duration);

	
	$("#background").css("background-image","url("+gif_bgs[next_bg]+")");
	$("#center").css("background-image","url("+gif_center[next_center]+")");

	next_bg 	= Math.floor( Math.random()*length_bgs );
	next_center = Math.floor( Math.random()*length_center );
	
	$("#load_bg").attr("src",gif_bgs[next_bg]);
	$("#load_center").attr("src",gif_center[next_center]);
}

function toggleInfo(){
	$("#info-overlay").toggleClass("show");
	$("#info-btn").toggleClass("show");
}

function check(){
	if (loaded > 1) {
		next_bg 	= Math.floor( Math.random()*length_bgs );
		next_center = Math.floor( Math.random()*length_center );
		next();
		$("#wrapper").click(next);
	}
}

function toggleSound(){
	if (muted) {
		muted = false;
		audio.muted = muted;
		$("#sound-btn").removeClass('muted');
	}else{
		muted = true;
		audio.muted = muted;
		$("#sound-btn").addClass('muted');
	}
	

}
function init() {
	
	$("#info-btn").click(toggleInfo);
	$("#sound-btn").click(toggleSound);

	$.ajax({
		url: "json/bg.json",
		cache: false,
		dataType: "json",
		success: function(d){
			gif_bgs = d;
			length_bgs = gif_bgs.length;
			loaded++;
			check();
		}
	});
	$.ajax({
		url: "json/center.json",
		cache: false,
		dataType: "json",
		success: function(d){
			gif_center = d;
			length_center = gif_center.length;
			loaded++;
			check();
		}
	});	
}

$(window).on("ready",init);

KillHour fucked around with this message at 19:55 on Dec 23, 2021

Ranzear
Jul 25, 2013

Don't forget the jquery include. It's a stretch to call it 'just javascript' at that point.

Volmarias
Dec 31, 2002

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

Ranzear posted:

Don't forget the jquery include. It's a stretch to call it 'just javascript' at that point.

As someone who used to write ye olde jovascrypte, there's absolutely nothing interesting jQuery does he, unless that's your point in which case whoosh.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Yeah that's all trivially replaced with vanilla.js.

Ranzear
Jul 25, 2013

Volmarias posted:

As someone who used to write ye olde jovascrypte, there's absolutely nothing interesting jQuery does he, unless that's your point in which case whoosh.

Yeah, that, sorta. jQuery is overkill here if not plainly bloat, and this code doesn't work without it, and including it might not be obvious to someone asking about this. I meant it as a direct caveat for the posted code. It's trivial without jq, but still different enough to matter.

There is nothing that rustles my jimmies like early programming courses teaching with jQuery.

Computer viking
May 30, 2011
Now with less breakage.

Ranzear posted:

Yeah, that, sorta. jQuery is overkill here if not plainly bloat, and this code doesn't work without it, and including it might not be obvious to someone asking about this. I meant it as a direct caveat for the posted code. It's trivial without jq, but still different enough to matter.

There is nothing that rustles my jimmies like early programming courses teaching with jQuery.

I mean, the first programming course I did taught us PHP 4. That may still have been the lesser sin, mind you.

(And then we had the "socket programming on linux with C" course shortly after, in parallel with "Flash and ActionScript", IIRC. Fun few years.)

birds
Jun 28, 2008


Hey all, this hotel I’m trying to book with their reward points makes it so it’s like trying to get a PS5 or 3080.

Basically I need to constantly check this page to see if the specific date I’m looking for switches to the 120k price point. Ideally this would be automated and I’d receive an alert if it becomes available. I see there are services and scripts geared towards finding things like graphics card stock but they don’t appear to work on this site.

https://bit.ly/3Jmfrxg

Any suggestions on where to start? I’m a total beginner but figure this could be at least an easy project.

Computer viking
May 30, 2011
Now with less breakage.

Oh that's kind of an ugly document - the nesting to get in to the value you want is what, fifteen levels deep?

Anyway. I'd suggest using something like Greasemonkey, which is a tool for managing and writing custom javascript that runs on a page. You can then write some JS to check the value, sleep for a while, reload, and check again - and then alert you if it drops below your threshold. I've never used greasemonkey, though - I have no idea what sort of notifications are available, or how it handles page reloads. It's a decade old by now, so presumably there are some tools available?

The actual scripting to pull out and compare the value is easy enough, if ugly. I'm using Firefox, but presumably you can do something similar in Chrome.
First, get the xpath to the value you want to monitor:
- Right click, inspect. This should pop up the inspector panel.
- Press the box+arrow in the top left of the inspector panel, or press ctrl+shift+C. This should put you in item selector mode, where hovering over things will highlight them. Click the price on the day you're interested in.
- This should highlight a line in the page source in the inspector panel - hopefully a line that ends with " 1,310,000</div>" or something like it.
- Right click that line, then copy/XPath in the popup.

This should copy an XPath selector for that element on the page - something like /html/body/div[1]/div/div/div/main/div/div/div[7]/div[2]/div[2]/div[1]/div. This is effectively the directions for how to get to that element, starting from the document root.

With that, the code is effectively "get the element at that path, strip out the commas, and see if that number is small enough".

I'm terrible at javascript, but something like this - though you obviously want to replace the path:
code:
var xp = "/html/body/div[1]/div/div/div/main/div/div/div[7]/div[2]/div[2]/div[1]/div[5]/div/button/div[3]/div[1]"
var res = document.evaluate(xp, document, null, XPathResult.ANY_TYPE, null)
var node = res.iterateNext()

if (node.innerHTML.replaceAll(",", "") < 1300000) {
	alert("Yay")
}
What's left as an exercise is wrapping that up in a sleep/reload/check loop and doing a more noticeable alert than a popup within that tab.

You can test that the above works by pasting it into the Console tab of the inspector. (You'll have to convince it that you're not just blindly pasting code from random people on the internet first - but it should be self-explanatory.)

Computer viking fucked around with this message at 05:16 on Dec 28, 2021

CarForumPoster
Jun 26, 2013

⚡POWER⚡

birds posted:

Hey all, this hotel I’m trying to book with their reward points makes it so it’s like trying to get a PS5 or 3080.

Basically I need to constantly check this page to see if the specific date I’m looking for switches to the 120k price point. Ideally this would be automated and I’d receive an alert if it becomes available. I see there are services and scripts geared towards finding things like graphics card stock but they don’t appear to work on this site.

https://bit.ly/3Jmfrxg

Any suggestions on where to start? I’m a total beginner but figure this could be at least an easy project.

Are there any langs you're comfortable with? This would be a reasonably easy selenium + python that you could make a little task on your computer to run on login or something...each time you login it fires up a browser to check prices then does something to notify you if it finds what you want.

This is basically the same as Computer viking's solution except python focused. Windows has a built in task manager for the running of the code that's straightforward. Could prob also make it auto open a chrome window too.

Computer viking
May 30, 2011
Now with less breakage.

I also quickly checked with my BF, who is the web person here.

His suggestions:
- Use violentMonkey, it's the still-opensource replacement for greasemonkey
- Each day is a Button element. Those button elements contain both "which date is this about" (in a field called "data-testid") and a screen reader hint that contains the points value (aria-label)
- This means you can use a querySelector to ask for "a button where the data-testid is a given date".

Putting it all together, this mess pulls out the points value for the 6th:
code:
var price = document.querySelector('button[data-testid="arrival-2022-12-06"]').
    getAttribute("aria-label").match("[0-9,]{3,15}").toString().replaceAll(",", "")
The .match part is a regexp that looks for "a string made up of only digits or commas, 3-15 characters long" - the full aria-label is something like "December 6 through December 7, 1,310,000 Points per night for 1 night. Premium Room Rewards. Choose room".

He also insisted that you use a long refresh timer, like 30 minutes, just to be polite. And that you put in a sanity check of the type "if it's 2022, stop" - so it doesn't accidentally keep running forever.

Computer viking fucked around with this message at 05:46 on Dec 28, 2021

Gin_Rummy
Aug 4, 2007
Can anyone recommend a really good primer/tutorial on creating a SQL database and linking it to a webapp?

I've been working on web-based a board game using JS/React, and I think I have my core game and its mechanics all programmatically established, but I want to store a huge array of trivia questions/answers in a database that can be called from my javascript functions.

KillHour
Oct 28, 2007


I'm almost positive your idea of "huge" isn't too large for a JSON file.

12 rats tied together
Sep 7, 2006

There are a lot of "better" ways to solve that problem but, since you asked specifically, the way to hook your webapp up to a database usually depends on the web server. It's abnormal to have client side javascript executing DB queries directly.

In something like Flask, you follow the steps outlined in the documentation section labeled define and access the database. Rails has a similar pattern. How are you currently running server side code?

CarForumPoster
Jun 26, 2013

⚡POWER⚡

KillHour posted:

I'm almost positive your idea of "huge" isn't too large for a JSON file.

AWS Lambda + a json file and some quick code to look poo poo up = an API made in 1 hour to return answers, infinitely scalable, costs nothing at the start.

Then you dont have to learn anything about databases!
AND NOT LEARNING IS HALF THE BATTLE!!!!!

(I am no good at databases so I don't have a good answer, I use python/django + sqlalchemy/pandas for all my poo poo because I am a crappy coder.)

Computer viking
May 30, 2011
Now with less breakage.

Gin_Rummy posted:

Can anyone recommend a really good primer/tutorial on creating a SQL database and linking it to a webapp?

I've been working on web-based a board game using JS/React, and I think I have my core game and its mechanics all programmatically established, but I want to store a huge array of trivia questions/answers in a database that can be called from my javascript functions.
I'd use python and Flask, which is a fairly simple framework for handling HTTP requests. Basically, you set up a python function to handle requests to a specific URL, use python code to talk to the database, and return JSON. However, it's hard to find a clean tutorial for that - they are all "how to orchestrate a docker image in the cloud while using this ORM layer to avoid writing SQL".

If you do want to go that way, you can piece it together yourself by looking at the python+database code separate from the Flask part: It's not hard to query a database from python.
There's also a json package that makes it trivial to create json text from a python object, so the complete flow would be something like this:

- receive a GET request on /question/
- Use SQL to get one or more rows from the database
- Put the results in a suitable python object - probably a list where each entry is a dictionary that represents a question
- Convert that to JSON text
- return a HTTP response with the JSON as the body

I'd use PostgreSQL as the database and the psycopg package in python to talk to it, but that is probably wildly overkill in this case - you may be better off with sqlite.
It's also very common to use SQLAlchemy - it's a python package that abstracts away which specific database you're using, which is useful if you ever want to migrate. It also does ORM - basically, you create python classes that represent the database tables, and it generates the SQL queries for you in the background. It seems nice, but it is one more thing to learn. Then again, so is SQL.

e: Django fills some of the same niche as Flask here, but it does a lot more for you, for good or bad. Which could be a good thing.

Computer viking fucked around with this message at 00:26 on Dec 30, 2021

Gin_Rummy
Aug 4, 2007

Computer viking posted:

I'd use python and Flask, which is a fairly simple framework for handling HTTP requests. Basically, you set up a python function to handle requests to a specific URL, use python code to talk to the database, and return JSON. However, it's hard to find a clean tutorial for that - they are all "how to orchestrate a docker image in the cloud while using this ORM layer to avoid writing SQL".

If you do want to go that way, you can piece it together yourself by looking at the python+database code separate from the Flask part: It's not hard to query a database from python.
There's also a json package that makes it trivial to create json text from a python object, so the complete flow would be something like this:

- receive a GET request on /question/
- Use SQL to get one or more rows from the database
- Put the results in a suitable python object - probably a list where each entry is a dictionary that represents a question
- Convert that to JSON text
- return a HTTP response with the JSON as the body

I'd use PostgreSQL as the database and the psycopg package in python to talk to it, but that is probably wildly overkill in this case - you may be better off with sqlite.
It's also very common to use SQLAlchemy - it's a python package that abstracts away which specific database you're using, which is useful if you ever want to migrate. It also does ORM - basically, you create python classes that represent the database tables, and it generates the SQL queries for you in the background. It seems nice, but it is one more thing to learn. Then again, so is SQL.

e: Django fills some of the same niche as Flask here, but it does a lot more for you, for good or bad. Which could be a good thing.

This sounds like exactly what I am looking for. I guess I’ll just flip to the next CS50x video that covers Flask and see where that gets me, unless you know a better/quicker overview of the framework?

In response to the rest, it’s probably true that a database is overkill for my application, but I’d rather learn this side of it now so I can flip right around apply that knowledge to bigger and better things.

Computer viking
May 30, 2011
Now with less breakage.

Try the quickstart, tutorial, and documentation from the flask project itself, it's not bad.

Volguus
Mar 3, 2009

Gin_Rummy posted:

This sounds like exactly what I am looking for. I guess I’ll just flip to the next CS50x video that covers Flask and see where that gets me, unless you know a better/quicker overview of the framework?

In response to the rest, it’s probably true that a database is overkill for my application, but I’d rather learn this side of it now so I can flip right around apply that knowledge to bigger and better things.

Go with sqllite for now. Trivial to setup (none to do) and you still have to learn SQL. Later you can go to bigger and more capable databases.

Computer viking
May 30, 2011
Now with less breakage.

Yeah, sqlite is great for this sort of thing. Postgres is a lot more work to set up, but also has some clear advantages - none of which matter at all for what you're doing.

Gin_Rummy
Aug 4, 2007

Computer viking posted:

Yeah, sqlite is great for this sort of thing. Postgres is a lot more work to set up, but also has some clear advantages - none of which matter at all for what you're doing.

What if I want to try a frinkiac-esque application as my next project? Would it be better to learn something like Postgres now on the easier/smaller scale concept to apply to that?

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Gin_Rummy posted:

What if I want to try a frinkiac-esque application as my next project? Would it be better to learn something like Postgres now on the easier/smaller scale concept to apply to that?

Unless you want to specialize as a DBA, you should stick to standard SQL and avoid the platform specific extensions.

SQLite and Postgres both conform to standards. Just use SQLite until you have a measured reason to migrate to anything else.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

leper khan posted:

Just use SQLite until you have a measured reason to migrate to anything else.

This is excellent advice.

Gin_Rummy
Aug 4, 2007
Thanks all! I went with the Flask/SQLite approach and got a simple little database set up... but now I've hit a bit of a brick wall in how I actually link the React front end to my backend. I can't really find a good guide that doesn't seem to just jump right into all sorts of post/get/fetch request type stuff without really explaining what is going on. Anyone know a good starting point I could try to take a look at?

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Gin_Rummy posted:

Thanks all! I went with the Flask/SQLite approach and got a simple little database set up... but now I've hit a bit of a brick wall in how I actually link the React front end to my backend. I can't really find a good guide that doesn't seem to just jump right into all sorts of post/get/fetch request type stuff without really explaining what is going on. Anyone know a good starting point I could try to take a look at?

Flask is a web framework. You are using flask to expose web apis that return the data that your react app that they would want. Single page applications (e.g. react) communicate with the web server by making ajax requests to web apis.

Say that say you have a react app that's intended to display a list of cars. In flask, you would make a web api that returns the data (maybe something like GET cars.) The react app would make an ajax request to GET the cars from this api, and display it on the page.

Ask a question about the above and I might be able to direct you to a more appropriate resource.

Gin_Rummy
Aug 4, 2007

Bruegels Fuckbooks posted:

Flask is a web framework. You are using flask to expose web apis that return the data that your react app that they would want. Single page applications (e.g. react) communicate with the web server by making ajax requests to web apis.

Say that say you have a react app that's intended to display a list of cars. In flask, you would make a web api that returns the data (maybe something like GET cars.) The react app would make an ajax request to GET the cars from this api, and display it on the page.

Ask a question about the above and I might be able to direct you to a more appropriate resource.

So my Flask app creates a “template” page, which I assume is basically what my API would be, right? Right now I just have it listing everything one after the other, but I could give it some sort of JSON structure or something if I need to.

Unrelated to that, I am also totally green on the “Ajax requests” bit of your post, if you have a good resource for that.

Gin_Rummy fucked around with this message at 18:29 on Dec 31, 2021

nielsm
Jun 1, 2009



Your application would consist of two parts:

1) A client-side user interface (frontend), written in HTML and JavaScript, probably using some JS framework to make it all easier to manage.
This part is how the user interacts with your app/game.

2) A server-side web service (backend), in your case written with Flask and more.
This part has various functions, exposed via a web API, to get various data involved in your game, and maybe hold game state and verify the players are making valid plays. For example, it could have one endpoint that returns a random question to the client, and another endpoint where the client sends the question-id and player's answer and gets a response whether the answer was correct or not. If your game has players move via a dice roll, you might also want to put the dice rolling on the backend, to make sure the player can't influence the dice roll by modifying the client (and cheat that way).
The backend might also hold a canonical version of the game state, which could be shared between multiple clients on multiple devices to allow remote multiplayer. When the client sends a "answer question" call, the backend could then not just tell the client whether it was correct, but also update the players' scores and update the client on the new scores or positions on the playing board.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Gin_Rummy posted:

So my Flask app creates a “template” page, which I assume is basically what my API would be, right? Right now I just have it listing everything one after the other, but I could give it some sort of JSON structure or something if I need to.

Unrelated to that, I am also totally green on the “Ajax requests” bit of your post, if you have a good resource for that.

Ok so let's start with the react side and ajax requests.

This goes over the background of the ajax request and how javascript running in the browser uses ajax requests to get information.
https://en.wikipedia.org/wiki/Ajax_(programming)

Now we need understand how react is related to this concept:

React is a framework for creating singe page applications
https://en.wikipedia.org/wiki/Single-page_application

So now that we know what react is, how do we use ajax with it?

https://reactjs.org/docs/faq-ajax.html
https://www.pluralsight.com/guides/how-to-handle-ajax-with-react

Now let's go back to flask. The flask template page is basically "hey, I access this url, and it gives me back an entire website." That's sort of the web 1.0 way of doing things (like a cgi script) - flask exposes a url, you access it in the browser, flask makes the page, gives it back.

React is different in that react isn't being served by the template page, it's a single page application living wherever it might go. You could think of it even as a different site. To communicate with flask, you as the developer write apis (just urls that expose the data, you could put [url]http://[/url][server]/[route] and see this list in the browser if you were so inclined)
https://towardsdatascience.com/creating-restful-apis-using-flask-and-python-655bad51b24

So going back to the car example, if your react app wants to list the cars, you need an api that has a list of the cars in json. In flask, you make an api that if you access website/cars, it returns a json list of the cars (this would be accessible by going to a url on the webserver.) This list would come from code you wrote using flask querying the database and serializing the returned results.

So summary - with flask, you're writing code that lists out the data that's accessible through a url. React (which is running in the browser) gets this data by accessing these urls using ajax requests.

Dominoes
Sep 20, 2007

I never understood the micro framework thing. Eg Flask, its "blazingly-fast" alternatives that are now mostly unmaintained or any of its clones in Rust etc. To get it to do stuff most websites use, you need to bolt together third party components, and hope they all work together. Compatibility/depdendency-hell, and/or wheel reinvention. Django is much smoother once you get past the learning curve.

Computer viking
May 30, 2011
Now with less breakage.

Flask is great if you just want to write a layer that makes a database available over http - django feels like overkill if you're not doing much beyond that. Besides, I don't like ORMs, but that's more of a personal falling.

Adbot
ADBOT LOVES YOU

Dominoes
Sep 20, 2007

Flask makes sense for that case. My concern is geared towards websites.

I also completely understand the not liking ORMs: They're DSLs. (Why not use and get good at the universal lang they all wrap?) And can do expensive queries if you're not careful. On the other hand, automatic migrations are sublime.

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