Author Topic: Getting players clan.  (Read 4229 times)

mRokita

  • Autococker
  • Posts: 598
Getting players clan.
« on: February 13, 2014, 12:16:30 PM »
Hello!
I have just wrote a simple python script that gets clan name and tag of a specified id.
It doesnt support ids with no clans or more than 1 clan yet, but please let me to finish it myself, so i dont allow editing my script yet. Feel free to use it in your own scripts.
Code: [Select]
import urllib2

def getclan(id):
   response = urllib2.urlopen("http://dplogin.com/index.php?action=viewmember&playerid="+str(id))
   page = response.read()
   page = page.split("\n")
   line = page[79]
   phase1 = line.split('href="')
   phase2 = phase1[1]
   phase2 = phase2.split('">')
   phase3 = phase2[1].split("</a></td></tr>")
   link = phase2[0]
   response1 = urllib2.urlopen(("http://dplogin.com" + link))
   clanpage = response1.read()
   clanpage = clanpage.split("\n")
   cphase1=clanpage[78]
   cphase1=cphase1.split('\t<tr><td><b class="faqtitle">Clan Tag:</b></td><td>')
   cphase2=cphase1[1]
   cphase2=cphase2.split("</td></tr>\r")
   cphase2=cphase2[0]
   return [phase3[0], cphase2]
   #(c) OriginalProgramming (M1CH43L) 2014

Usage:

Code: [Select]
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
>>> getclan(210227)
['team.dgit', '#dgit|']
>>> getclan(5006)
['Clan Prozak', '[cP]']
>>> getclan(200335)
['Exzotic Gaming', '-ExZ.']
>>> getclan(5641)
['Get your own Root!', '-rOOt-']

//EDIT: Works properly with Python 2.7, it wasnt tested on Python 3.3.
You can download python 2.7 for free here.

xrichardx

  • 68 Carbine
  • Posts: 295
Re: Getting players clan.
« Reply #1 on: February 13, 2014, 12:47:27 PM »
Nice work, but I think just doing one regex would be much easier to read (less than half the lines) and much more effective.

ViciouZ

  • Map Committee
  • Autococker
  • Posts: 2227
Re: Getting players clan.
« Reply #2 on: February 13, 2014, 12:50:52 PM »
You may find this useful in future https://code.google.com/p/py-dom-xpath/

not_payl_obviously

  • 68 Carbine
  • Posts: 415
Re: Getting players clan.
« Reply #3 on: February 13, 2014, 01:21:48 PM »
You may find this useful in future https://code.google.com/p/py-dom-xpath/
Does this thing support HTML 4.01? Seems like DPLogin is using HTML 4.01.

Nice work, but I think just doing one regex would be much easier to read (less than half the lines) and much more effective.
It wouldn't be more effective if you mean speed: It would be quite slower but speed isn't main problem here whatsoever.

This could be helpful: http://stackoverflow.com/questions/11709079/parsing-html-python

mRokita

  • Autococker
  • Posts: 598
Re: Getting players clan.
« Reply #4 on: February 13, 2014, 01:49:06 PM »
Nice work, but I think just doing one regex would be much easier to read (less than half the lines) and much more effective.
Splitting '\n's takes some time. I can change it but it think 2 sec isnt bad.
If you think that its a important problem to fix, i can do it but imo it isnt that important.
//edit
Maybe page.find("x")?
I think it will be slower than splitting but i can test it.

xrichardx

  • 68 Carbine
  • Posts: 295
Re: Getting players clan.
« Reply #5 on: February 13, 2014, 03:06:18 PM »
It wouldn't be more effective if you mean speed: It would be quite slower but speed isn't main problem here whatsoever.

Code: [Select]
import urllib2
import time
import re

response = urllib2.urlopen("http://dplogin.com/index.php?action=viewmember&playerid=123850")
website = response.read()
response = urllib2.urlopen("http://dplogin.com/index.php?action=viewclan&clanid=15233")
website2 = response.read()

starttime = time.clock()

for i in range (10000):
    page = website
    page = page.split("\n")
    line = page[79]
    phase1 = line.split('href="')
    phase2 = phase1[1]
    phase2 = phase2.split('">')
    phase3 = phase2[1].split("</a></td></tr>")
    link = phase2[0]
    clanpage = website2
    clanpage = clanpage.split("\n")
    cphase1=clanpage[78]
    cphase1=cphase1.split('\t<tr><td><b class="faqtitle">Clan Tag:</b></td><td>')
    cphase2=cphase1[1]
    cphase2=cphase2.split("</td></tr>\r")
    cphase2=cphase2[0]

endtime = time.clock()
print ("Method one returned: " + phase3[0] + ", " + cphase2)
print ("Time taken: " + str(endtime - starttime))

starttime = time.clock()

regexclan = re.compile (re.escape('Active Clan:</b></td><td><a href="/index.php?action=viewclan&clanid=') + '(\d+)' + re.escape('">') + '(.+)' + re.escape('</a>'))
regextag = re.compile (re.escape("Clan Tag:</b></td><td>") + "(.+)\<\/td\>")

for i in range (10000):
    page = website
    clanpage = website2
    resultclan = regexclan.search (page)
    resulttag = regextag.search (clanpage)
   
endtime = time.clock()
print ("Method two returned: " + resultclan.group(2) + ", " + resulttag.group (1))
print ("Time taken: " + str(endtime - starttime))

produces

Code: [Select]
Method one returned: Crack-Gaming, cRack'
Time taken: 0.153514297266
Method two returned: Crack-Gaming, cRack'
Time taken: 0.0985314502412

on my machine. I don't know how 0.10 seconds taken is quite slower than 0.15 seconds. If I don't measure the re.compile time (because when you do it properly and object oriented, then this would be done on object initialization and not when it comes to the performance critical part) - then it's even faster (by about 0.01 second).

Edit:
Also it's funny how you think databases work.
Also, it's funny how you think regular expressions and string split functions work.
« Last Edit: February 13, 2014, 04:01:50 PM by xrichardx »

mRokita

  • Autococker
  • Posts: 598
Re: Getting players clan.
« Reply #6 on: February 13, 2014, 03:58:52 PM »
imo 0.1 sec doesnt matter :P

not_payl_obviously

  • 68 Carbine
  • Posts: 415
Re: Getting players clan.
« Reply #7 on: February 13, 2014, 03:59:16 PM »
on my machine. I don't know how 0.010 seconds taken is quite slower than 0.015 seconds. If I don't measure the re.compile time (because when you do it properly and object oriented, then this would be done on object initialization and not when it comes to the performance critical part) - then it's even faster (by about 0.001 second).
Wow, you showed me how wrong I am. Do you feel better now? I surely hope so, now you won't have to cry that I told you your bot was DoSing forum.
If you weren't that stupid maybe I would talk about your results seriously, but you show how low you are. So please don't try to take me to your obviously lower level.

EDIT:
imo 0.1 sec doesnt matter :P
Quote from: Me
speed isn't main problem here whatsoever.
He just had to show me how wrong I am because he is crybaby...

Anyway both regexp and split approach is just bad, you should instead parse HTML tree and take values from there (because then small changes on website won't matter then).

xrichardx

  • 68 Carbine
  • Posts: 295
Re: Getting players clan.
« Reply #8 on: February 13, 2014, 04:19:03 PM »
imo 0.1 sec doesnt matter :P
I totally agree with you, but I hate it when payl spreads wrong facts just to make others look wrong and feel great. I just wanted to tell you that your solution is really hard to understand if you do not have the site source in front of you and that you could just use regexes, which will be much easier to unterstand, which would also need less lines and also do it a little bit faster because the site code doesn't have to be scanned through as often as it has to be with string.split:
Nice work, but I think just doing one regex would be much easier to read (less than half the lines) and much more effective.

not_payl_obviously

  • 68 Carbine
  • Posts: 415
Re: Getting players clan.
« Reply #9 on: February 13, 2014, 04:24:34 PM »
little bit faster because the site code doesn't have to be scanned through as often as it has to be with string.split:
Well, this is obviously wrong. He only scans whole website once (first split), then he is operating on one line. That's why I assumed it would be faster, but seems like first split is taking longer than expected.

Quote
I hate it when payl spreads wrong facts just to make others look wrong and feel great.
That's why you are crybaby? Oh well...

Quote
much more effective.
Quote
I totally agree with you(0.1sec isn't big difference)
:)

But right xrichardx, now you have right to "spread wrong facts just to make others look wrong and feel great".

xrichardx

  • 68 Carbine
  • Posts: 295
Re: Getting players clan.
« Reply #10 on: February 14, 2014, 08:07:58 AM »
   
   little bit faster because the site code doesn't have to be scanned through as often as it has to be with string.split:
   
Well, this is obviously wrong. He only scans whole website once (first split), then he is operating on one line. That's why I assumed it would be faster, but seems like first split is taking longer than expected.
How is a part of the website source not "site code"? I did not specify the parts of the website the program has to go through and I did not say that it goes through the whole source more than once. I just said that it goes through the "site code" more often - and one line of the website source is obviously "site code". I don't see how this is obvously wrong.
You like to assume and expect, don't you? Probably you should start to rely on facts instead of assuming and expecting. For a professional programmer like you say you are it shouldn't be that hard to test it.

That's why you are crybaby? Oh well...
:)
I said A, you assumed that A is wrong and B is right, I proved that A is right and B is wrong so now I am the "crybaby". I think saying that somebody is a crybaby is much more the behaviour of a crybaby because it shows that you are out of arguments and can only start to insult.

Edit: Hint: When I said "much more effective" I focused on lines needed to do the work that has to be done, time needed to do the work and easy it will be for other people to understand the source code. I did not only focus on time.

But right xrichardx, now you have right to "spread wrong facts just to make others look wrong and feel great".
So, please tell me where I did that.

not_payl_obviously

  • 68 Carbine
  • Posts: 415
Re: Getting players clan.
« Reply #11 on: February 14, 2014, 10:03:22 AM »
Well, this is obviously wrong. He only scans whole website once (first split), then he is operating on one line. That's why I assumed it would be faster, but seems like first split is taking longer than expected.

How is a part of the website source not "site code"? I did not specify the parts of the website the program has to go through and I did not say that it goes through the whole source more than once. I just said that it goes through the "site code" more often - and one line of the website source is obviously "site code". I don't see how this is obvously wrong.
Yeah well, string operation on one line surely take long. lulz. Obviously you saying that those operations took long is wrong, split took long. So still, this code haven't gone by code many times, It in fact operated on one line which was fast, but split itself was main drawback.

Quote
I said A, you assumed that A is wrong and B is right, I proved that A is right and B is wrong so now I am the "crybaby". I think saying that somebody is a crybaby is much more the behaviour of a crybaby because it shows that you are out of arguments and can only start to insult.
Oh yes, you surely are not crybaby because you were crying so much about me saying your bot DoSed forum :) . Now you are just showing that this is true.

Quote
Edit: Hint: When I said "much more effective" I focused on lines needed to do the work that has to be done, time needed to do the work and easy it will be for other people to understand the source code. I did not only focus on time.
Sure ;> . But you confirmed when I assumed that "effective" you meant "fast". But right, now when I assumed "fast" you changed your mind. Oh well, you just show that you had no idea what you meant.

Quote
So, please tell me where I did that.
I already told you that, right now you are trying to defend your opinion with more lies. Oh well, too bad I detected it.

Btw. "Probably you should start to rely on facts instead of assuming and expecting." Yeah, because I haven't changed meaning of my post depending on what we are talking about (When it turned out your method is bit faster: "effective" -> "fast". But then after you confirmed change isn't big, you meant "effecitve" -> "easy to write" :> ).

EDIT: Oh forgot to tell you: YHBT. gg.

mRokita

  • Autococker
  • Posts: 598
Re: Getting players clan.
« Reply #12 on: February 14, 2014, 03:04:35 PM »
Guys, stop flaming.
If you want to do it, simply start a new topic for it.