Skip to main content

Kaip išsirinkti telefoną už 1 lt iš tele2 svetainės?

Mano sesuo nusprendė pirkti telefoną iš tele2, už 1 lt. Paprašė manęs pagalbos surasti geriausią.

Atsidaręs tele2 svetainę neradau jokio normalaus palyginimo pagal kainas, todėl į pagalbą pasitelkiau python. Pasirašiau tokį scriptuką:

#!/usr/bin/env python
# encoding: utf-8

import re, os.path
from urllib import urlopen, quote

phones = {
    'Sony Ericsson':
        ['K310i', 'K530i (3G)', 'K550i', 'K600i', 'K800i (3G)', 'P1i (3G)',
         'S500i', 'T250i', 'T650i (3G)', 'W200i', 'W580i', 'W880i (3G)',
         'W950i', 'Z310i', 'Z530i', 'Z610i (3G)'],

    'Nokia':
        ['2610', '3109 classic', '3110 Classic', '5070', '5200', '5300',
         '6020', '6030', '6060', '6070', '6080', '6085', '6103',
         '6110 Navigator', '6111', '6120 classic (3G)', '6125', '6131',
         '6151 (3G)', '6230i', '6233 (3G)', '6267 (3G)', '6288 (3G)',
         '6290 (3G)', '6300', '6500', '7360', '7373', '7390 (3G)',
         '7500 Prism', '8600 Luna', 'E50 (FOTO)', 'E61 (3G)', 'E65 (3G)',
         'E70 (3G)', 'N70 (3G)', 'N73 (3G)', 'N80 (3G)', 'N90-1 (3G)',
         'N95 (3G)'],

    'Motorola':
        ['K1', 'L6', 'U6', 'V3', 'W375'],

    'Samsung':
        ['SGH-C300', 'SGH-D830', 'SGH-E210', 'SGH-E250', 'SGH-E390',
         'SGH-E740', 'SGH-E900', 'SGH-G600', 'SGH-U300', 'SGH-U700 (3G)',
         'SGH-X500', 'SGH-X510', 'SGH-X520', 'SGH-Z150(3G)',
         'SGH-Z230 (3G)', 'SGH-Z400 (3G)'],

    'LG':
        ['KE500', 'KE800 Chocolate', 'KE970 Shine', 'KG245', 'KG800',
         'KP200'],
}

pattern = re.compile(r'<tr>'
                     r'<td class="price_type">Privatiems klientams</td>'
                     r'<td class="price_value" align="center">(\d+) Lt'
                     r'<td class="price_value" align="center">(\d+) Lt'
                     r'<td class="price_value" align="center">(\d+) Lt')

cnt = 0
for phone, models in phones.iteritems():
    for model in models:
        filename = "phone__%s--%s.html" % (quote(phone), quote(model))
        if os.path.exists(filename):
            data = file(filename).read()
        else:
            url = ('http://www.tele2.lt/cps/rde/xchg/tele2_lt/hs.xsl'
                   '/367_LTH_HTML.html/papp/handsets_lt/'
                   'http://handsets.tele2.lt/handsets.phtml?'
                   'manuf=%s&model=%s') % (quote(phone), quote(model))
        data = urlopen(url).read()
        file(filename, 'w').write(data)

        results = pattern.search(data)
        if results:
            price1, price2, price3 = results.groups()
            if int(price1) <= 50 or int(price2) <= 50 or int(price3) <= 50:
                print(("%-15s %-18s %5s Lt, %5s Lt, %5s Lt. "
                       "file:///tmp/%s") % (phone, model, price1, price2,
                                            price3, filename))
                cnt += 1

print("\nViso rasta telefonų: %d" % cnt)

Tai gi šio nedidelio scripto pagalba turėjau visas telefonų kainas vienoje vietoje ir galėjau lengvai išsirinkti norimą telefoną.

Šiuo scriptu galite pasinaudoti ir jūs. Tereikia turėti įdiegtą python’ą, tada susikurti failą, kurio turinys būtų toks koks pateiktas višuje ir paleisti tą naujai sukurtą failą su python. Paleisti reikėtu iš komandinės eilutės, nes būtent joje bus atvaizduotas rezultatas.