Forum Groups
  All forums
    Help & Feedback
      Questions
      Work in progress
      Finished Art
      Non-Max related
    Community
      Offtopic
      News
    Hardware
    Photography



Maxunderground news unavailable

[Python] - parsing raw python code from website
show user profile  9krausec
So I'm on a mission to figure out a way to have a small chunk of Python code point to a URL with a larger amount of Python code, strip the code from the URL and then run it in the buffer locally on the computer.

I'm confident I'll be able to figure out a way to do this, but seeing how it seems like most documentation is about how to fetch HTML elements (headers, usernames, passwords, variables in general) and not solid chunks of code.

I wanted to ask here before I went out digging for the solution I should be educating myself on.

(Not asking out of laziness. This just seems like a more obscure thing to do and I'm not very sure what to even be searching for. Many of my searches come up about Urllib which is used to strip individual HTML elements and push them into variables locally).

Many thanks for any points in the right direction.

-9k

edit: so far I'm checking into something called Beautiful Soup mixed with Urllib.




- Portfolio-




read 403 times
1/11/2016 5:26:55 PM (last edit: 1/11/2016 5:36:40 PM)
show user profile  gogodr
use requests. http://docs.python-requests.org/en/latest/
then all you need to do is this:

mycode = requests.get("http://example.com/code.txt")
exec mycode

----------

if what you want is to get some code from the html, then treat it just as a giant string and search on it. with substrings or regex.

Hello there

beautiful ;3


read 387 times
1/11/2016 6:35:28 PM (last edit: 1/11/2016 6:36:47 PM)
show user profile  9krausec
Thank you so much for the info gogodr.

Very happy I asked as I was building a much more complex solution than that (and would of wasted a lot of time figuring that it was the wrong solution).

I'll give your suggestion an attempt tomorrow probably. I want to set this up on square space, which I assume is possible since you can push in your own custom HTML.

Thanks much again.




- Portfolio-




read 380 times
1/11/2016 6:47:00 PM (last edit: 1/11/2016 6:47:00 PM)
show user profile  gogodr
happy to help. :)

Hello there

beautiful ;3


read 375 times
1/11/2016 6:51:48 PM (last edit: 1/11/2016 6:51:48 PM)
show user profile  9krausec
@gogodr - looking into your suggestion now.

Is there a way to do this without manually installing the python module? At the end of the day I'm trying to do this with out of the box Maya which communicates with python 2.7.6

I'm definitely trying to avoid any actions by the user to set this up with the exception of running one .PY file to initiate the pull from the website (and execute the code).

Right now for the test page I have setup-
http://clayton-krause.squarespace.com/tempdump

which is a hidden page on my temp square space site. The second chunk of text on there is a mock class I wrote up with one function that is simply to print out a line of code for testing purposes.

with the "Requests: Http for humans" it looks like you need to manually download a module and place it within python.

Thanks for any further advice!

edit: corrected the above.. Maya ships out with 2.7.6. PIP isn't bundled with Python until 2.7.9. It sounds like Pip is some module installer that allows for the user to do what I need to do. I'm going to look into this further, but any pointers would be great in the meantime.





- Portfolio-




read 340 times
1/13/2016 7:14:00 PM (last edit: 1/13/2016 7:18:40 PM)
show user profile  9krausec
I think I found what I was looking for gang -
http://techartsurvival.blogspot.com/2014/05/your-weekly-moment-of-python-is-awesome.html

Thanks for all the help though Gogodr. I should of been more specific with my original post. Sorry about that.




- Portfolio-




read 333 times
1/13/2016 7:47:15 PM (last edit: 1/13/2016 7:47:15 PM)
show user profile  gogodr
pip is the packet manager, if you have python, you have pip.
all you needed to do to install requests was to run once
pip install requests
it will download the module you need and then you can bundle it with your installation.
hope that helps

Hello there

beautiful ;3


read 319 times
1/14/2016 12:30:49 AM (last edit: 1/14/2016 12:31:23 AM)
#Maxforums IRC
Open chat window


Support Maxforums.org