Ver código fonte

catch timing error if less than 1d remaining

Johann Woelper 6 anos atrás
pai
commit
45235e77c7
4 arquivos alterados com 86 adições e 62 exclusões
  1. 65 41
      db.json
  2. 1 2
      index.html
  3. 2 1
      urls.json
  4. 18 18
      watcher.py

+ 65 - 41
db.json

@@ -3,118 +3,142 @@
         "url": null, 
         "price": null, 
         "thumb": null, 
-        "desc": "2019-05-25 09:24:05.589451"
+        "desc": "2019-05-27 16:47:44.410557"
     }, 
     "Springfield Armory M1A Loaded - M14": {
         "thumb": "http://www.egun.de/market/images/picture.gif", 
-        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190602T210600%2F20190602T213600&text=Springfield+Armory+M1A+Loaded+-+M14&location=&details=", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190602T210400%2F20190602T213400&text=Springfield+Armory+M1A+Loaded+-+M14&location=&details=", 
         "url": "http://egun.de/market/item.php?id=7487317", 
-        "price": 346.0, 
-        "remaining": "8 Tage", 
+        "price": 676.0, 
+        "remaining": "6 Tage", 
         "desc": "Springfield Armory M1A Loaded - M14"
     }, 
     "Mossberg MVP Patrol .223Rem. 16\" Lauf 10 RD Mag.Neuwaffe": {
         "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=", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190601T173400%2F20190601T180400&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", 
+        "remaining": "5 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=", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190620T124900%2F20190620T131900&text=egun&location=&details=", 
         "url": "http://egun.de/market/item.php?id=7480984", 
         "price": 1399.0, 
-        "remaining": "26 Tage", 
+        "remaining": "23 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=", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190607T223600%2F20190607T230600&text=egun&location=&details=", 
         "url": "http://egun.de/market/item.php?id=6929139", 
         "price": 799.0, 
-        "remaining": "13 Tage", 
+        "remaining": "11 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=", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190529T143300%2F20190529T150300&text=MSZU+Auktion+Mossberg+MVP+Patrol+.308Win&location=&details=", 
         "url": "http://egun.de/market/item.php?id=7460544", 
-        "price": 336.33, 
-        "remaining": "4 Tage", 
+        "price": 378.0, 
+        "remaining": "1 Tage", 
         "desc": "MSZU Auktion Mossberg MVP Patrol .308Win"
     }, 
     "Accuracy International Chassis System (AICS-AX 2.0) FDE Remington 700 SA .308 Repetierb\u00fcchsen": {
         "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=", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190602T010000%2F20190602T013000&text=egun&location=&details=", 
         "url": "http://egun.de/market/item.php?id=7020521", 
         "price": 1419.0, 
-        "remaining": "7 Tage", 
+        "remaining": "5 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": {
         "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=", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190623T224100%2F20190623T231100&text=egun&location=&details=", 
         "url": "http://egun.de/market/item.php?id=7234684", 
         "price": 899.0, 
-        "remaining": "29 Tage", 
+        "remaining": "27 Tage", 
         "desc": "Rep.B\u00fcchse .223Rem Mossberg MVP Patrol TAN 16,25\" Lauf/ MFD/ M\u00fcndungsgewinde 1/2-28/ AR-15 Magazin"
     }, 
-    "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"
+    "Harris Zweibein 1A2-LM H\u00f6he 9-13\"/ ca. 23-33cm/ Rastenverstellung/ gummierte F\u00fc\u00dfe": {
+        "thumb": "http://egun.de/market/cache/aucimg/64x64/5.7474724.408757137.jpg", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190609T164800%2F20190609T171800&text=egun&location=&details=", 
+        "url": "http://egun.de/market/item.php?id=7474724", 
+        "price": 108.95, 
+        "remaining": "13 Tage", 
+        "desc": "Harris Zweibein 1A2-LM H\u00f6he 9-13\"/ ca. 23-33cm/ Rastenverstellung/ gummierte F\u00fc\u00dfe"
     }, 
     "Accuracy International AX Chassis System gr\u00fcn": {
         "thumb": "http://www.egun.de/market/images/picture.gif", 
-        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190529T111900%2F20190529T114900&text=egun&location=&details=", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190529T111700%2F20190529T114700&text=egun&location=&details=", 
         "url": "http://egun.de/market/item.php?id=7102212", 
         "price": 1495.0, 
-        "remaining": "4 Tage", 
+        "remaining": "1 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": {
+        "thumb": "http://egun.de/market/cache/aucimg/64x64/1.6935206.608219153.jpg", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190624T222200%2F20190624T225200&text=egun&location=&details=", 
+        "url": "http://egun.de/market/item.php?id=6935206", 
+        "price": 1399.0, 
+        "remaining": "28 Tage", 
+        "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=", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190618T130500%2F20190618T133500&text=egun&location=&details=", 
         "url": "http://egun.de/market/item.php?id=6884512", 
         "price": 670.0, 
-        "remaining": "24 Tage", 
+        "remaining": "21 Tage", 
         "desc": "B&T GRS Gewehr Schalld\u00e4mpfer .308 + B&T Kompensator - Accuracy International M18x1,5 Br\u00fcgger Thomet"
     }, 
     "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=", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190529T153300%2F20190529T160300&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", 
+        "price": 355.0, 
+        "remaining": "1 Tage", 
         "desc": "MSZU Auktion Mossberg MVP Patrol .308Win Nummer Zwei"
     }, 
+    "Harris Zweibein 1A2-L: H\u00f6he 9-13\"/ ca. 23-33cm, stufenlos einstellbar, gummierte F\u00fc\u00dfe": {
+        "thumb": "http://egun.de/market/cache/aucimg/64x64/2.7081930.306653604.jpg", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190622T152500%2F20190622T155500&text=egun&location=&details=", 
+        "url": "http://egun.de/market/item.php?id=7081930", 
+        "price": 108.95, 
+        "remaining": "25 Tage", 
+        "desc": "Harris Zweibein 1A2-L: H\u00f6he 9-13\"/ ca. 23-33cm, stufenlos einstellbar, gummierte F\u00fc\u00dfe"
+    }, 
     "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=", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190623T224000%2F20190623T231000&text=egun&location=&details=", 
         "url": "http://egun.de/market/item.php?id=6483093", 
         "price": 799.0, 
-        "remaining": "29 Tage", 
+        "remaining": "27 Tage", 
         "desc": "Rep.B\u00fcchse .308Win Mossberg MVP Patrol Black 16,25\" Lauf/ MFD/ M\u00fcndungsgewinde 5/8-24/ SR-25 Magazin"
     }, 
+    "MSZU Auktion Harris Zweibein 9\"-13\" 1A2-L": {
+        "thumb": "http://www.egun.de/market/images/picture.gif", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190614T121700%2F20190614T124700&text=MSZU+Auktion+Harris+Zweibein+9%22-13%22+1A2-L&location=&details=", 
+        "url": "http://egun.de/market/item.php?id=7481474", 
+        "price": 23.5, 
+        "remaining": "17 Tage", 
+        "desc": "MSZU Auktion Harris Zweibein 9\"-13\" 1A2-L"
+    }, 
     "Ruger Gunsite Scout Rifle .308 Win Mit M\u00fcndungsfeuerd\u00e4mpfer, Matchabzug 200g, Zweibein Neuwertig!!!": {
         "thumb": "http://www.egun.de/market/images/picture.gif", 
-        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190527T222800%2F20190527T225800&text=egun&location=&details=", 
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190527T210400%2F20190527T213400&text=egun&location=&details=", 
         "url": "http://egun.de/market/item.php?id=7407520", 
         "price": 1199.0, 
-        "remaining": "2 Tage", 
+        "remaining": "05:40", 
         "desc": "Ruger Gunsite Scout Rifle .308 Win Mit M\u00fcndungsfeuerd\u00e4mpfer, Matchabzug 200g, Zweibein Neuwertig!!!"
     }, 
-    "Magazin f\u00fcr Accuracy AE": {
+    "Norinco M1A": {
         "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"
+        "end_date": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190602T184400%2F20190602T191400&text=Norinco+M1A&location=&details=", 
+        "url": "http://egun.de/market/item.php?id=7495131", 
+        "price": 499.0, 
+        "remaining": "6 Tage", 
+        "desc": "Norinco M1A"
     }
 }

+ 1 - 2
index.html

@@ -48,7 +48,6 @@
     
     <div class="content">
       
-      
       <template v-for="item in items" v-if="item.price != null">
         <div class="panel">
           <div class="grid-auto">
@@ -60,7 +59,7 @@
               <div class="badge">{{item.price}} EUR</div>
             </div>
             <div>Noch {{item.remaining}}</div>
-	    <a v-bind:href="item.end_date">Add to cal</a>
+      <a v-bind:href="item.end_date">Add to cal</a>
 	  </div>
         </div>
       </template>

+ 2 - 1
urls.json

@@ -6,5 +6,6 @@
     "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&query=accuracy&quick=1"
+    "http://egun.de/market/list_items.php?mode=qry&query=accuracy&plusdescr=off&wheremode=and&ewb=&status=&minprice=300&maxprice=&type=0&nick=&country_id=&zip=&int=0&order=ends&asdes=asc",
+    "http://egun.de/market/list_items.php?mode=qry&plusdescr=off&wheremode=and&query=harris+1A2-L&quick=1"
 ]

+ 18 - 18
watcher.py

@@ -6,6 +6,7 @@ import datetime
 import time
 import argparse
 import urllib
+import traceback
 
 # TODO output price, url image
 
@@ -36,10 +37,12 @@ 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
+            print traceback.format_exc()
+            print(e)
         self.dump()
 
     def load_urls(self):
@@ -100,27 +103,24 @@ 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)
+                                    # This is all so dirty. If Time is not days, they show the hours, so try...
+                                    try:
+                                        days = int(cell.text.split()[0])
+                                    except:
+                                        days = 0
+                                        hours, minutes = hours_minutes.split(":")    
+
+                                    if days > 0:    
+                                        for c in cell.iter():
+                                            hours_minutes = c.tail
+                                        hours, minutes = hours_minutes.split(":")
+                                    #print hours, minutes
+                                    start_d = datetime.datetime.now() + datetime.timedelta(days=days, minutes=int(minutes), hours=int(hours))
                                     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], 'end_date': _end_date}
 
@@ -132,7 +132,7 @@ if __name__ == "__main__":
     parser.add_argument('--loop', action='store_true', default=False, help='if set, loop forever')
     args = parser.parse_args()
 
-    print "Starting"
+    print("=== Starting")
     while True:
         r = Retriever()
         if not args.loop: