Beispiel #1
0
def main():

    mailcount = int(cache.get("evec_mail_count"))
    mailsend = cache.get("evec_mail_sent")

    if mailsend is None:
        mailsend = 0
        cache.set("evec_mail_sent", "0")

    mailsend = int(mailsend)

    #print "Count",mailcount,"at",mailsend

    message = "price,volRemaining,typeID,range,orderID,volEntered,minVolume,bid,issued,duration,stationID,regionID,solarSystemID,jumps,source\n"
    #message = "CSV Header\n"

    if mailsend >= mailcount:
        return False

    thispass = 0
    cont = False # Continue?
    while mailsend < mailcount:
        mailsend += 1
        thispass += 1
        cache.incr("evec_mail_sent")
        try:
            message = message + cache.get("evec_mail_" + str(mailsend))
        except:
            pass
#        if thispass > 50:
#            cont = True
#            break

    smtpsess = smtplib.SMTP('localhost')
    datae = "To: [email protected]\nPrecedence: bulk\nX-EVEC-UserIdHash: 0" + "\nSubject: Upload\n\n" + message
    smtpres = smtpsess.sendmail('*****@*****.**', '*****@*****.**', datae)
    return cont
Beispiel #2
0
    def inputdata(self, typename=None, userid=None, data=None, typeid = None, region = None, **kw):

        response = ""

        if userid is None:
            userid = 0
        else:
            userid = long(userid)

        db = evec_func.db_con()

        if data is None:
            return ""

        data = data.split("\n")

        del data[0] # header
        ndata = []
        mailcount = cache.incr("evec_mail_count")
        cache.set("evec_mail_" + str(mailcount), "\n".join(data), expire = 3600)


        # chunk the CSV file

        for line in data:
            if len(line) > 1:
                ndata.append(line.split(','))
        data = ndata

        cur = db.cursor()

        if not typeid and not region:
            try:
                line = data[0]
                typeid = line[2]
                region = line[11]
            except:
                return

        response += "Beginning your upload of "+typename+"\n"
        response += "TypeID: " + typeid + " RegionID: " + region + "\n"
        #cur.execute('SET TRANSACTION ISOLATION LEVEL READ COMMITTED')

        cur.execute('DELETE FROM current_market WHERE typeid = %s AND regionid = %s', [typeid, region])

        derived_region = 0
        derived_typeid = 0
        has_new_data = False

        for line in data:
            typeid = line[2]
            region = line[11]

            derived_typeid = typeid
            derived_region = region

            bid = line[7]
            if bid == "True":
                bid = 1
            else:
                bid = 0

            station = line[10]
            system = line[12]
            source = "evec_upload_cache"

            try:
                source = line[14]
            except:
                pass

            self.station_check(db, station = station, system = system, region = region)


            cur.execute("""
            INSERT INTO current_market (regionid, systemid, stationid, typeid,
            bid,price, orderid, minvolume, volremain, volenter, issued, duration, range, reportedby)
            VALUES( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)


            """, [region, line[12], line[10], typeid, `bid`, line[0], line[4], line[6],
                  int(float(line[1])), line[5], line[8], line[9]+" days", line[3], 0])

            cur.execute("SELECT count(orderid) FROM archive_market WHERE orderid = %s AND volremain = %s AND regionid = %s", [ line[4], int(float(line[1])), region])
            hasdata = cur.fetchone()
            hasdata = hasdata[0]
            if hasdata == 0:
                has_new_data = True
                cur.execute("""
                            INSERT INTO archive_market (regionid, systemid, stationid, typeid,
                            bid,price, orderid, minvolume, volremain, volenter, issued, duration, range, reportedby, source)
                            VALUES( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
                            """, [region, line[12], line[10], typeid, `bid`, line[0], line[4], line[6],
                                  int(float(line[1])), line[5], line[8], line[9]+" days", line[3], 0, source])


        db.commit()
        db.close()
        response += "Complete! Thank you for your contribution to EVE-Central.com!"
        if derived_region != 0 and derived_typeid != 0:
            # Schedule a background queue action to recompute statistics
            self.stat_queue.put((region, typeid))


        return response
    def inputdata(self,typename=None,userid=None,data=None,**kw):

        response = ""

        if userid is None:
            userid = 0
        else:
            userid = long(userid)

        db = evec_func.db_con()

        if data is None:
            return ""

        # Send e-mail to the update push list




        #smtpsess = smtplib.SMTP('localhost')
        #datae = "To: [email protected]\nPrecedence: bulk\nX-EVEC-UserIdHash: " + hexdigest + "\nSubject: Upload\n\n" + data
        #smtpres = smtpsess.sendmail('*****@*****.**', '*****@*****.**', datae);


        data = data.split("\n")

        del data[0] # header
        ndata = []
        mailcount = cache.incr("evec_mail_count")
        cache.set("evec_mail_" + str(mailcount), "\n".join(data), expire = 3600)


        # chunk the CSV file

        for line in data:
            if len(line) > 1:
                ndata.append(line.split(','))
        data = ndata

        cur = db.cursor()

        try:
            line = data[0]
            typeid = line[2]
            region = line[11]
        except:
            return

        response += "Beginning your upload of "+typename+"\n"
        response += "TypeID: " + typeid + " RegionID: " + region + "\n"
        #cur.execute('SET TRANSACTION ISOLATION LEVEL READ COMMITTED')

        # Pre-validate the data coming in
        for line in data:
            if long(typeid) != long(line[2]):
                print "REJECT due to mismatched typeids"
                return # fail
            cur.execute('SELECT typeid,regionid FROM current_market WHERE orderid = %s', [line[4]])
            r = cur.fetchone()
            if r:
                if long(r[0]) != long(typeid) or long(r[1]) != long(region):
                    print "REJECT due to mismatched typeids in DB - type",r[0],"==",typeid," or ",r[1], "==", region
                    return # invalid data


        #cur.execute('LOCK TABLE users IN SHARE ROW EXCLUSIVE MODE')

        #cur.execute('UPDATE users SET uploads = uploads + 1 WHERE userid = %s', [userid])
        #db.commit()


        cur.execute('DELETE FROM current_market WHERE typeid = %s AND regionid = %s', [typeid, region])
        #db.commit()


        derived_region = 0
        derived_typeid = 0
        has_new_data = False

        for line in data:
            typeid = line[2]
            region = line[11]

            derived_typeid = typeid
            derived_region = region

            bid = line[7]
            if bid == "True":
                bid = 1
            else:
                bid = 0

            station = line[10]
            system = line[12]
            source = "evec_upload_cache"

            try:
                source = line[14]
            except:
                pass

            self.station_check(db, station = station, system = system, region = region)


            cur.execute("""
            INSERT INTO current_market (regionid, systemid, stationid, typeid,
            bid,price, orderid, minvolume, volremain, volenter, issued, duration, range, reportedby)
            VALUES( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)


            """, [region, line[12], line[10], typeid, `bid`, line[0], line[4], line[6],
                  int(float(line[1])), line[5], line[8], line[9]+" days", line[3], 0])

            cur.execute("SELECT count(orderid) FROM archive_market WHERE orderid = %s AND volremain = %s AND regionid = %s", [ line[4], int(float(line[1])), region])
            hasdata = cur.fetchone()
            hasdata = hasdata[0]
            if hasdata == 0:
                has_new_data = True
                cur.execute("""
                            INSERT INTO archive_market (regionid, systemid, stationid, typeid,
                            bid,price, orderid, minvolume, volremain, volenter, issued, duration, range, reportedby, source)
                            VALUES( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
                            """, [region, line[12], line[10], typeid, `bid`, line[0], line[4], line[6],
                                  int(float(line[1])), line[5], line[8], line[9]+" days", line[3], 0, source])


        db.commit()
        db.close()
        response += "Complete! Thank you for your contribution to EVE-Central.com!"
        if derived_region != 0 and derived_typeid != 0:
            # Schedule a background queue action to recompute statistics
            self.stat_queue.put((region, typeid))


        return response