Johann Woelper 7 роки тому
батько
коміт
b14f2e543e
4 змінених файлів з 149 додано та 45 видалено
  1. 93 37
      db.json
  2. 3 2
      index.html
  3. 3 3
      urls.json
  4. 50 3
      watcher.py

+ 93 - 37
db.json

@@ -3,62 +3,118 @@
         "url": null, 
         "price": null, 
         "thumb": null, 
-        "desc": "2019-02-11 09:00:02.289679"
+        "desc": "2019-05-25 09:24:05.589451"
     }, 
-    "Schaft f\u00fcr Ruger Gunsite Scout Rifle": {
-        "url": "http://egun.de/market/item.php?id=7337107", 
-        "remaining": "26 Tage", 
-        "price": 69.0, 
+    "Springfield Armory M1A Loaded - M14": {
         "thumb": "http://www.egun.de/market/images/picture.gif", 
-        "desc": "Schaft f\u00fcr Ruger Gunsite Scout Rifle"
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190602T210600%2F20190602T213600&text=Springfield+Armory+M1A+Loaded+-+M14&location=&details=", 
+        "url": "http://egun.de/market/item.php?id=7487317", 
+        "price": 346.0, 
+        "remaining": "8 Tage", 
+        "desc": "Springfield Armory M1A Loaded - M14"
     }, 
     "Mossberg MVP Patrol .223Rem. 16\" Lauf 10 RD Mag.Neuwaffe": {
-        "url": "http://egun.de/market/item.php?id=7312600", 
-        "remaining": "12 Tage", 
-        "price": 819.0, 
         "thumb": "http://www.egun.de/market/images/picture.gif", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190601T173600%2F20190601T180600&text=Mossberg+MVP+Patrol+.223Rem.+16%22+Lauf+10+RD+Mag.Neuwaffe&location=&details=", 
+        "url": "http://egun.de/market/item.php?id=7463911", 
+        "price": 819.0, 
+        "remaining": "7 Tage", 
         "desc": "Mossberg MVP Patrol .223Rem. 16\" Lauf 10 RD Mag.Neuwaffe"
     }, 
+    "Rep.B\u00fcchse .308Win Ruger Gunsite Scout LH LINKS 16,1\" Lauf/M\u00fcndungsfeuerd\u00e4mpfer (5/8-24)/Schichtholz": {
+        "thumb": "http://egun.de/market/cache/aucimg/64x64/2.7480984.1452304817.jpg", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190620T125100%2F20190620T132100&text=egun&location=&details=", 
+        "url": "http://egun.de/market/item.php?id=7480984", 
+        "price": 1399.0, 
+        "remaining": "26 Tage", 
+        "desc": "Rep.B\u00fcchse .308Win Ruger Gunsite Scout LH LINKS 16,1\" Lauf/M\u00fcndungsfeuerd\u00e4mpfer (5/8-24)/Schichtholz"
+    }, 
+    "Rep.B\u00fcchse .223Rem Mossberg MVP Patrol Black 16,25\" Lauf/ MFD/ M\u00fcndungsgewinde 1/2-28/ AR-15 Magazin": {
+        "thumb": "http://egun.de/market/cache/aucimg/64x64/4.6929139.1343167511.jpg", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190607T223700%2F20190607T230700&text=egun&location=&details=", 
+        "url": "http://egun.de/market/item.php?id=6929139", 
+        "price": 799.0, 
+        "remaining": "13 Tage", 
+        "desc": "Rep.B\u00fcchse .223Rem Mossberg MVP Patrol Black 16,25\" Lauf/ MFD/ M\u00fcndungsgewinde 1/2-28/ AR-15 Magazin"
+    }, 
+    "MSZU Auktion Mossberg MVP Patrol .308Win": {
+        "thumb": "http://www.egun.de/market/images/picture.gif", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190529T143500%2F20190529T150500&text=MSZU+Auktion+Mossberg+MVP+Patrol+.308Win&location=&details=", 
+        "url": "http://egun.de/market/item.php?id=7460544", 
+        "price": 336.33, 
+        "remaining": "4 Tage", 
+        "desc": "MSZU Auktion Mossberg MVP Patrol .308Win"
+    }, 
     "Accuracy International Chassis System (AICS-AX 2.0) FDE Remington 700 SA .308 Repetierb\u00fcchsen": {
-        "url": "http://egun.de/market/item.php?id=7020521", 
-        "remaining": "14 Tage", 
-        "price": 1448.0, 
         "thumb": "http://www.egun.de/market/images/picture.gif", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190602T010100%2F20190602T013100&text=egun&location=&details=", 
+        "url": "http://egun.de/market/item.php?id=7020521", 
+        "price": 1419.0, 
+        "remaining": "7 Tage", 
         "desc": "Accuracy International Chassis System (AICS-AX 2.0) FDE Remington 700 SA .308 Repetierb\u00fcchsen"
     }, 
     "Rep.B\u00fcchse .223Rem Mossberg MVP Patrol TAN 16,25\" Lauf/ MFD/ M\u00fcndungsgewinde 1/2-28/ AR-15 Magazin": {
-        "url": "http://egun.de/market/item.php?id=7234684", 
-        "remaining": "20 Tage", 
-        "price": 979.0, 
         "thumb": "http://egun.de/market/cache/aucimg/64x64/1.7234684.1225321523.jpg", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190623T224300%2F20190623T231300&text=egun&location=&details=", 
+        "url": "http://egun.de/market/item.php?id=7234684", 
+        "price": 899.0, 
+        "remaining": "29 Tage", 
         "desc": "Rep.B\u00fcchse .223Rem Mossberg MVP Patrol TAN 16,25\" Lauf/ MFD/ M\u00fcndungsgewinde 1/2-28/ AR-15 Magazin"
     }, 
-    "Remington 700 AAC-SD Repetierb\u00fcchse 308 win": {
-        "url": "http://egun.de/market/item.php?id=7228926", 
-        "remaining": "5 Tage", 
-        "price": 699.0, 
+    "MAUSER SR L96 oder Accuracy AW.308 AW.338 oder X-9 Airsoft Sniper oder ARES GAS-Version": {
+        "thumb": "http://egun.de/market/cache/aucimg/64x64/6.5737017.1231488210.jpg", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190615T142000%2F20190615T145000&text=MAUSER+SR+L96+oder+Accuracy+AW.308+AW.338+oder+X-9+Airsoft+Sniper+oder+ARES+GAS-Version&location=&details=", 
+        "url": "http://egun.de/market/item.php?id=5737017", 
+        "price": 179.9, 
+        "remaining": "21 Tage", 
+        "desc": "MAUSER SR L96 oder Accuracy AW.308 AW.338 oder X-9 Airsoft Sniper oder ARES GAS-Version"
+    }, 
+    "Accuracy International AX Chassis System gr\u00fcn": {
         "thumb": "http://www.egun.de/market/images/picture.gif", 
-        "desc": "Remington 700 AAC-SD Repetierb\u00fcchse 308 win"
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190529T111900%2F20190529T114900&text=egun&location=&details=", 
+        "url": "http://egun.de/market/item.php?id=7102212", 
+        "price": 1495.0, 
+        "remaining": "4 Tage", 
+        "desc": "Accuracy International AX Chassis System gr\u00fcn"
     }, 
-    "Rep.B\u00fcchse .308Win Ruger Gunsite Scout 16,1\" Lauf/ M\u00fcndungsfeuerd\u00e4mpfer (5/8-24)/ Schichtholzschaft": {
-        "url": "http://egun.de/market/item.php?id=6935206", 
-        "remaining": "3 Tage", 
-        "price": 1399.0, 
-        "thumb": "http://egun.de/market/cache/aucimg/64x64/1.6935206.608219153.jpg", 
-        "desc": "Rep.B\u00fcchse .308Win Ruger Gunsite Scout 16,1\" Lauf/ M\u00fcndungsfeuerd\u00e4mpfer (5/8-24)/ Schichtholzschaft"
+    "B&T GRS Gewehr Schalld\u00e4mpfer .308 + B&T Kompensator - Accuracy International M18x1,5 Br\u00fcgger Thomet": {
+        "thumb": "http://www.egun.de/market/images/picture.gif", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190618T130700%2F20190618T133700&text=egun&location=&details=", 
+        "url": "http://egun.de/market/item.php?id=6884512", 
+        "price": 670.0, 
+        "remaining": "24 Tage", 
+        "desc": "B&T GRS Gewehr Schalld\u00e4mpfer .308 + B&T Kompensator - Accuracy International M18x1,5 Br\u00fcgger Thomet"
     }, 
-    "Remington 700 AAC-SD mit 16,5\" Lauf .300 Blackout und Hausken JD184 Schalld\u00e4mpfer": {
-        "url": "http://egun.de/market/item.php?id=7166449", 
-        "remaining": "13 Tage", 
-        "price": 1799.0, 
-        "thumb": "http://egun.de/market/cache/aucimg/64x64/5.7166449.1389141865.jpg", 
-        "desc": "Remington 700 AAC-SD mit 16,5\" Lauf .300 Blackout und Hausken JD184 Schalld\u00e4mpfer"
+    "MSZU Auktion Mossberg MVP Patrol .308Win Nummer Zwei": {
+        "thumb": "http://www.egun.de/market/images/picture.gif", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190529T153500%2F20190529T160500&text=MSZU+Auktion+Mossberg+MVP+Patrol+.308Win+Nummer+Zwei&location=&details=", 
+        "url": "http://egun.de/market/item.php?id=7460618", 
+        "price": 353.0, 
+        "remaining": "4 Tage", 
+        "desc": "MSZU Auktion Mossberg MVP Patrol .308Win Nummer Zwei"
     }, 
-    "Mossberg MVP Patrol .308win 16\" Lauf 10 RD Mag.Neuwaffe": {
-        "url": "http://egun.de/market/item.php?id=7312591", 
-        "remaining": "12 Tage", 
-        "price": 819.0, 
+    "Rep.B\u00fcchse .308Win Mossberg MVP Patrol Black 16,25\" Lauf/ MFD/ M\u00fcndungsgewinde 5/8-24/ SR-25 Magazin": {
+        "thumb": "http://egun.de/market/cache/aucimg/64x64/2.6483093.93081809.jpg", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190623T224200%2F20190623T231200&text=egun&location=&details=", 
+        "url": "http://egun.de/market/item.php?id=6483093", 
+        "price": 799.0, 
+        "remaining": "29 Tage", 
+        "desc": "Rep.B\u00fcchse .308Win Mossberg MVP Patrol Black 16,25\" Lauf/ MFD/ M\u00fcndungsgewinde 5/8-24/ SR-25 Magazin"
+    }, 
+    "Ruger Gunsite Scout Rifle .308 Win Mit M\u00fcndungsfeuerd\u00e4mpfer, Matchabzug 200g, Zweibein Neuwertig!!!": {
         "thumb": "http://www.egun.de/market/images/picture.gif", 
-        "desc": "Mossberg MVP Patrol .308win 16\" Lauf 10 RD Mag.Neuwaffe"
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190527T222800%2F20190527T225800&text=egun&location=&details=", 
+        "url": "http://egun.de/market/item.php?id=7407520", 
+        "price": 1199.0, 
+        "remaining": "2 Tage", 
+        "desc": "Ruger Gunsite Scout Rifle .308 Win Mit M\u00fcndungsfeuerd\u00e4mpfer, Matchabzug 200g, Zweibein Neuwertig!!!"
+    }, 
+    "Magazin f\u00fcr Accuracy AE": {
+        "thumb": "http://www.egun.de/market/images/picture.gif", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190530T143800%2F20190530T150800&text=egun&location=&details=", 
+        "url": "http://egun.de/market/item.php?id=6158802", 
+        "price": 119.0, 
+        "remaining": "5 Tage", 
+        "desc": "Magazin f\u00fcr Accuracy AE"
     }
 }

+ 3 - 2
index.html

@@ -60,7 +60,8 @@
               <div class="badge">{{item.price}} EUR</div>
             </div>
             <div>Noch {{item.remaining}}</div>
-          </div>
+	    <a v-bind:href="item.end_date">Add to cal</a>
+	  </div>
         </div>
       </template>
       
@@ -80,4 +81,4 @@
   :root {
     --main-color: #2e442f;
   }
-</style>
+</style>

+ 3 - 3
urls.json

@@ -1,10 +1,10 @@
 [
     "http://www.egun.de/market/list_items.php?mode=qry&query=m1a&plusdescr=off&wheremode=and&ewb=1&status=&minprice=&maxprice=1900&type=0&nick=&country_id=&zip=&int=0&order=ends&asdes=asc",
-    "http://www.egun.de/market/list_items.php?mode=qry&plusdescr=off&wheremode=and&query=remington+aac&quick=1",
     "http://www.egun.de/market/list_items.php?mode=qry&query=ruger+scout&plusdescr=off&wheremode=and&ewb=1&status=&minprice=&maxprice=&type=0&nick=&country_id=&zip=&int=0&order=ends&asdes=asc",
     "http://www.egun.de/market/list_items.php?mode=qry&query=aics&plusdescr=off&wheremode=and&ewb=&status=&minprice=200&maxprice=&type=0&nick=&country_id=&zip=&int=0&order=ends&asdes=asc",
     "http://www.egun.de/market/list_items.php?mode=qry&plusdescr=off&wheremode=and&query=mossberg+patrol&quick=1",
     "http://www.egun.de/market/list_items.php?mode=qry&query=smith+wesson+r8&plusdescr=off&wheremode=and&ewb=1&status=&minprice=&maxprice=&type=0&nick=&country_id=&zip=&int=0&order=ends&asdes=asc",
     "http://www.egun.de/market/list_items.php?mode=qry&query=m305&plusdescr=off&wheremode=and&ewb=1&status=&minprice=&maxprice=&type=0&nick=&country_id=&zip=&int=0&order=ends&asdes=asc",
-    "http://www.egun.de/market/list_items.php?mode=qry&plusdescr=off&wheremode=and&maxprice=2000&query=m14+luxdef&quick=1"
-]
+    "http://www.egun.de/market/list_items.php?mode=qry&plusdescr=off&wheremode=and&maxprice=2000&query=m14+luxdef&quick=1",
+    "http://www.egun.de/market/list_items.php?mode=qry&plusdescr=off&wheremode=and&query=accuracy&quick=1"
+]

+ 50 - 3
watcher.py

@@ -5,9 +5,28 @@ from lxml import html, etree
 import datetime
 import time
 import argparse
+import urllib
 
 # TODO output price, url image
 
+def title(string):
+    t = "egun"
+    try:
+        t = urllib.quote_plus(string)
+    except:
+        pass
+
+    try:
+        t = urllib.quote_plus(string.split(" "))
+    except:
+        pass
+    
+    return t
+
+def utctime(dt):
+    return dt.strftime("%Y%m%dT%H%M00")
+
+
 class Retriever(object):
     def __init__(self):
         self.urls = []
@@ -17,23 +36,30 @@ class Retriever(object):
         self.base_url = 'http://egun.de/market/'
         self.json_out = {}
         self.load_urls()
-        self.scrape()
+        try:
+            self.scrape()
+        except Exception as e:
+            print e
         self.dump()
 
     def load_urls(self):
         with open(self.urlfile) as f:
             self.urls = json.load(f)
 
+
     def dump(self):
         with open(self.dbfile, 'w') as f:
             json.dump(self.json_out, f, indent=4)
 
     def scrape(self):
         self.json_out['Last update'] = {'thumb': None, 'desc': str(datetime.datetime.now()), 'price': None, 'url': None}
+        
         for url in self.urls:
+            #print url
             r = requests.get(url)
             tree = html.fromstring(r.content)
             for element in tree:
+                #print etree.tostring(element)
                 for e in element.iter():
                     if e.tag == 'tr' and 'bgcolor' in e.attrib:
                         if e.attrib['bgcolor'] == '#FFFFFF' or e.attrib['bgcolor'] == '#EBEBEB':
@@ -42,6 +68,7 @@ class Retriever(object):
                             _desc = ''
                             _url = ''
                             _price = 0
+                            _end_date = ''
 
                             # get thumb
                             for thumb in e.iter('img'):
@@ -72,11 +99,30 @@ class Retriever(object):
 
                             cells = []
                             for cell in e.iter('td'):
+                                if cell.attrib.get("align") == "center" and cell.attrib.get("nowrap") == "nowrap":
+                                    days = int(cell.text.split()[0])
+                                    for c in cell.iter():
+                                        hours_minutes = c.tail
+                                    hours,minutes = hours_minutes.split(":")
+                                    print "===", title(_desc)
+                                    print "\tnow", datetime.datetime.now()
+                                    # print days, hours, minutes
+                                    start_d = datetime.datetime.now() + datetime.timedelta(days=days, minutes = int(minutes), hours=int(hours))
+                                    print "\tstart", start_d
+                                    print "\tutcstart", utctime(start_d)
+                                    end_d = start_d + datetime.timedelta(minutes = 30)
+                                    calstring = "http://www.google.com/calendar/event?action=TEMPLATE&dates={}%2F{}&text={}&location=&details=".format(utctime(start_d), utctime(end_d), title(_desc))
+                                    print "\t", calstring
+                                    print "\n\n"
+                                    _end_date = calstring
+                                #print _end_date
+                                #for i in cell.iter():
+                                #    print i.text
                                 if cell.text is not None and cell.text != '':
                                     cells.append(cell.text)
           
 
-                            self.json_out[_desc] = {'thumb': _thumb, 'desc': _desc, 'price': _price, 'url': _url, 'remaining': cells[-1]}
+                            self.json_out[_desc] = {'thumb': _thumb, 'desc': _desc, 'price': _price, 'url': _url, 'remaining': cells[-1], 'end_date': _end_date}
 
 
 
@@ -90,5 +136,6 @@ if __name__ == "__main__":
     while True:
         r = Retriever()
         if not args.loop:
+            #print r.json_out
             break
-        time.sleep(600)
+        time.sleep(600)