예제 #1
0
def compose_tweet(user, params, con, replyto):
    if len(params) < 1:
        print("Usage: compose <text>")
        return

    text = " ".join(params)
    if len(text) > 80:
        print("Tweet too long.")
        return

    tdate = cx_Oracle.DateFromTicks(time.time())
    t = {
        'writer': user['usr'],
        'tdate': tdate,
        'text' : text,
        'tid' : None,
        'replyto' : replyto
    }

    # Generate ID
    got_tid = False
    while not got_tid:
        t["tid"] = random.randint(0, 2 ** 16) 
        if tq.get_tweet(t["tid"], con) is None:
            got_tid = True

    tq.save_tweet(t, con)

    for word in params:
        if word.startswith('#'):
            hashtag = word[1:]
            if tq.get_hashtag(hashtag, con) is None:
                tq.save_hashtag(hashtag, con)
            tq.save_mention(t, hashtag, con)
    print("Tweet Created")
예제 #2
0
def retweet(user,replyto,con):
    rdate = cx_Oracle.DateFromTicks(time.time())
    t = {
        'usr': user['usr'],
        'rdate': rdate,
        'tid' : replyto
    }
    tq.save_retweet(t,con)
    print("Retweeted!")
예제 #3
0
def save_follow(flwer, flwee, con):
    start_date = cx_Oracle.DateFromTicks(time.time())
    if int(flwer) == int(flwee):
        print("You can't follow yourself!")
        return
    run_post_query('create_follow', {
        "flwer": flwer,
        "flwee": flwee,
        "start_date": start_date
    }, con)
    print("Follow successful!")
예제 #4
0
파일: auditor.py 프로젝트: uve/shiva
    def get(self, param):

        cell_id = self.get_argument("cell_id", None)

        depart = self.get_argument("depart", None)

        typet = self.get_argument("typet", "0")
        tovar = self.get_argument("tovar", "0")
        mode = self.get_argument("mode", "0")

        out = self.cursor.var(cx_Oracle.CURSOR)

        if param == 'products':

            pos = int(self.get_argument("pos", 0))
            mask = self.get_argument("mask", None)

            res = self.proc("shiva.tovar_list", [mask, out])

            all_results = ['\n<complete add="true">']

            for item in res[-1].fetchall()[pos:]:
                value = '''<option value="%s">[%s] %s</option>''' % (
                    item[0], item[1], item[2])

                value = value.replace('&', '&amp;')

                all_results.append(value)

            all_results.append("</complete>")

            self.write_XML("\n".join(all_results))

            return

        if param == 'tovars':

            self.execute(
                "select id, code, name from tovar where hide=1 and typet=%s order by name"
                % typet)
            results = self.cursor.fetchall()

            self.write(results)

            return

        if param == 'head':

            if mode == '0':

                res = self.proc("shiva.GetRevisionSaldoCell",
                                [depart, tovar, out])

                all_results = fetchall(res[-1])

                self.write(all_results)
                return

            if mode == '1':

                epoch_time = int(time.time())

                data = cx_Oracle.DateFromTicks(epoch_time)
                obor = "+"

                #data_s = data_e = "26.08.2013"

                result = self.func('sclad.GetSaldoTovar',
                                   cx_Oracle.NUMBER,
                                   parameters=[tovar, depart, data, obor])

                isp = json.dumps(int(result))

                self.write(isp)

                return

            #Список остатков по партиям. Временно отключен!
            if mode == '2':

                sql = '''select p.party, p.num, to_char(p.data,'DD.MM.YYYY') data, p.inbox, tsclad.GetPartyOst(p.party,%s) saldo from party p  
                        where p.tovar=%s and tsclad.GetPartyOst(p.party,%s)>0''' % (
                    depart, tovar, depart)

                self.execute(sql)
                results = fetchall(self.cursor)

                self.write(results)

                return

        #Список остатков по партиям. Временно отключен!
        elif param == 'cell_history':

            res = self.proc("shiva.getpallethistory", [cell_id, out])

            all_results = fetchall(res[-1])

            self.write(all_results)
            return

            return

        ###### ПЕЧАТЬ ######

        elif param == 'print':

            sql = "select id, code, name from tovar where id=%s" % tovar

            self.execute(sql)
            result = fetchone(self.cursor)

            try:
                tovar_name = result["name"]
            except:
                tovar_name = ""

            try:
                tovar_code = result["code"]
            except:
                tovar_code = ""

            sql = '''Select tp.name, p.num, p.inbox, pp.tovar_place, 
                        shiva.GetSaldoCell(tp.id,Null) saldo,  to_char(p.data,'DD.MM.YYYY') data
                        from palet_place pp, sw_palete_party spp, party p, tovar_place tp
                        where  pp.tovar_place=tp.id and tp.depart in (3,16) and tp.status=1 and 
                        pp.end_date is Null and pp.palete=spp.palete and spp.party_id=p.party and 
                        p.tovar=%s
                        order by tp.name''' % tovar

            self.execute(sql)
            result_mode1 = fetchall_by_name(self.cursor)
            #result_mode1 = Executor.exec_cls(sql, pTovar=tovar, multi=True)

            total1 = sum(item["saldo"] for item in result_mode1)

            sql = '''select p.party, p.num, p.inbox, 
                         tsclad.GetPartyOst(p.party,3)+tsclad.GetPartyOst(p.party,16) saldo,
                         to_char(p.data,'DD.MM.YYYY') data
                         from party p 
                         where p.tovar=%s and 
                         tsclad.GetPartyOst(p.party,3)+tsclad.GetPartyOst(p.party,16)>0''' % tovar

            #result_mode2 = Executor.exec_cls(sql, pTovar=tovar, multi=True)
            result_mode2 = self.cursor.fetchall()

            total2 = sum(item["saldo"] for item in result_mode2)

            result = self.func('isclad.GetTovarSaldoSclad',
                               returnType=cx_Oracle.NUMBER,
                               parameters=[tovar, 1])
            total3 = json.dumps(int(result))

            loader = template.Loader(TEMPLATE_DIR)
            output = loader.load("auditor.html").generate(
                data1=result_mode1,
                total1=total1,
                data2=result_mode2,
                total2=total2,
                tovar_name=tovar_name,
                tovar_code=tovar_code,
                total3=total3)

            output = output.replace('\n', '').replace('\r', '')

            self.write({
                'cmd':
                '''self.Incunable(function(doc){ doc.write('%s') })''' % output
            })

        elif param == 'maketaskrevision':

            pRevision = cx_Oracle.NUMBER

            result = self.func('shiva.MakeTaskRevision',
                               returnType=[tovar, self.session.rc],
                               parameters=[pRevision])

            self.write({'info': 'Задание на ревизию сформировано'})

            return
예제 #5
0
 def test_1000_date_from_ticks(self):
     "1000 - test DateFromTicks()"
     today = datetime.datetime.today()
     timestamp = time.mktime(today.timetuple())
     date = oracledb.DateFromTicks(timestamp)
     self.assertEqual(date, today.date())
예제 #6
0
 def testDateFromTicks(self):
     "test DateFromTicks()"
     today = datetime.datetime.today()
     timestamp = time.mktime(today.timetuple())
     date = cx_Oracle.DateFromTicks(timestamp)
     self.assertEqual(date, today.date())