CODEX Posted September 23, 2010 Report Posted September 23, 2010 Nush daca e ceva interesant sau nu , daca se poate face ceva de aici sau nu , ma rog http://www.deviantart.com/global/difi/?c[]=%22%3E%3Cscript%3Ealert%28%27xss%27%29%3C/script%3E%22DeviationView%22%2C%22getExtrasHTML%22%2C[164532133%2C%22%22%2C{}]&t=e ceva sau nu ?ps: si ce e ala DiFi ? Quote
1337 Posted September 23, 2010 Report Posted September 23, 2010 DiFi nu o fi sistemul de search de la dArt? Nu prea sunt sanse. Quote
CODEX Posted September 23, 2010 Author Report Posted September 23, 2010 This little piece of Python code grabs the ID number for a random deviation from a particular users gallery. DiFi is used to grab the deviation ID numbers. Created by me.This was something I decided to create after doing some research into the DiFi used in deviantART. I discovered a way to grab the favourites of a particular user through DiFi, and wondered if I could do anything else involving the gallery of a deviant.DiFi works by sending a URL with your request in it, and you are given a response in a human-readable table, or another format if you choose it. The URL contains the query as c[]=class;method;parameters. After a while of playing around I found that when using DiFi to get deviations listed in a users gallery, class "Aggregations" and method "get_galleries_initial" are used. The parameters are 3 numbers separated by commas. The first parameter is always the user's ID number, so I used my own when testing.After playing around even more, I discovered that the second parameter generally refers to either the user's main gallery or their favourites, 20 and 21 respectively. The third parameter defines what is returned from those particular places. 0 returns a list of all the deviation IDs stored, and 1 will return extra information and ID numbers.Using Aggregations;get_galleries_initial;1570401,20,1 will return the ID numbers for my personal galleries (excluding favourites) and the HTML code used, I assume, to display the small section in the side bar which links to each gallery.To get the full list of deviations in my gallery I would use Aggregations;get_galleries_initial;1570401,20,0. That was all well and good, but I wanted to be able to get deviations from the galleries of other users too, so I needed to be able to get the user ID number of any deviant.I opened up the source code for my deviantART page and did a quick search to find the first instance of my user ID number. The first instance of my user ID was actually in some JavaScript that uses DiFi, and I thought that it would not be a good idea to use that as it looked as though that was only available when logged in, and would only allow one ID number to be used. I searched again and found an appropriate instance. The "first" instance appears in an HTML tag as below:<div class="thought block" id="c759213177" typeid="4" itemid="1570401">I needed to slice out the ID number, and I wasn't going to waste time searching for the whole tag in my Python code, so I decided only to search for 'itemid="' and '"' in that order. I made sure to confirm that this was also the first instance of itemid before doing so. On line 21 you can see the code used to slice out the ID number.Seeing as I had a way to grab a user's ID number easily, I thought I should get on and do the part which actually gets a deviation ID number. Cue DiFi.I needed the data returned by the DiFi request to be parsable, so returning it as xml was the best and only format to use without having to download alternate extensions for Python. So, the DiFi request I am using is below:Aggregations;get_galleries_initial;devid,20,0&t=xml"t" refers to "type", so the code requests the data to be returned in a format type of "xml". Simple enough! But then I have to parse the xml.The way python is parsed in Python makes it quite awkward to return the values without the xml tags attached, but simple slicing the strings in the right places seems to work fine.Deviation ID numbers are wrapped in <ids></ids> in the returned code, but the numeric order of the deviation ID is also wrapped in the same way, which again, makes things awkward. It's easy to tell, however, that the deviation ID numbers are in even tags, and the order in odd tags. So the deviation ID numbers are stored in <ids> 2, 4, 6, 8, 10, 12 etc. To get around this, when generating a random number, I add 1 to it if the number is odd. This means I can get the right number without reading it to check.Finally, I decided to put this code into a function so that it can be easily reused.Thanks for reading! I hope you feel more knowledgeable about grabbing random deviation ID numbers through DiFi in Python!If you want to read more about DiFi you can visit the botdom documentation Wiki to read our (limited) documentation on DiFi ;p<EDIT id='1'>I've changed it so that it uses the JSON returned by DiFi. This means no more parsing XML tags and all that stuff! I've also made it possible to return more than one thumb id number at a time, and all of them are returned in a list!</EDIT><EDIT id='2'>I've changed the last bit of the code. There used to be around five lines of code, and I've reduced it to one line. Python is quite nifty methinks.</EDIT><EDIT id='3'>It now works with Python 3.0! And I'm using the JSON decoder rather than eval. Using eval is naughty!</EDIT>am gasit ceva despre difi Quote