Python论坛  - 讨论区

标题:[python-chinese] (no subject)

2005年07月30日 星期六 23:09

Schopendauer Nietzsche mosquitoxh at yahoo.com.cn
Sat Jul 30 23:09:35 HKT 2005

Skipped content of type multipart/alternative-------------- next part --------------
#! /usr/local/bin/python
# -*- coding: iso-8859-15 -*-

import sys
import smtplib
import codecs
from email.MIMEText import MIMEText

from types import *

sys.path.append('/home/logix/DCOracle2')
import DCOracle2

db = DCOracle2.connect("lmusr/future2 at TMSPROD_PROD")

c = db.cursor()

sqlstr = "select                                                                                            \
	 decode(grouping(group_cd),1,'总',decode(grouping(dc_nm),1,group_cd,'  ')) group_cd,                \
	 decode(grouping(group_cd),1, '合计',decode(grouping(dc_nm),1,'小计',to_char(dc_nm))) dc_cd,         \
	 to_char(sum(cur_qty_bd_ctv),'FM999,999,999') cur_qty_bd_ctv,                                        \
	 to_char(sum(cur_qty_sb_ctv),'FM999,999,999') cur_qty_sb_ctv,                                        \
	 to_char(sum(cur_qty_bd_rac),'FM999,999,999') cur_qty_bd_rac,                                        \
	 to_char(sum(cur_qty_sb_rac),'FM999,999,999') cur_qty_sb_rac,                                        \
	 to_char(sum(cur_qty_BD_mwo),'FM999,999,999') cur_qty_BD_mwo,                                        \
	 to_char(sum(cur_qty_sb_mwo),'FM999,999,999') cur_qty_sb_mwo,                                        \
	 to_char(sum(cur_qty_bd_wm),'FM999,999,999') cur_qty_bd_wm,                                          \
	 to_char(sum(cur_qty_sb_wm),'FM999,999,999') cur_qty_sb_wm,                                          \
	 to_char(sum(cur_qty_bd_ref),'FM999,999,999') cur_qty_bd_ref,                                        \
	 to_char(sum(cur_qty_sb_ref),'FM999,999,999') cur_qty_sb_ref,                                        \
	 to_char(sum(cur_qty_bd_dvd),'FM999,999,999') cur_qty_bd_dvd,                                        \
	 to_char(sum(cur_qty_sb_dvd),'FM999,999,999') cur_qty_sb_dvd,                                        \
	 to_char(sum(cur_qty_bd_dva),'FM999,999,999') cur_qty_bd_dva,                                        \
	 to_char(sum(cur_qty_sb_dva),'FM999,999,999') cur_qty_sb_dva,                                        \
	 to_char(sum(cur_qty_bd_vc),'FM999,999,999') cur_qty_bd_vc,                                          \
	 to_char(sum(cur_qty_sb_vc),'FM999,999,999') cur_qty_sb_vc,                                          \
	 to_char(sum(cur_qty_bd_etc),'FM999,999,999') cur_qty_bd_etc,                                        \
	 to_char(sum(cur_qty_sb_etc),'FM999,999,999') cur_qty_sb_etc,                                        \
	 to_char(sum(cur_qty_bd_ctv)+sum(cur_qty_bd_rac)+sum(cur_qty_BD_mwo)+                                \
	 		sum(cur_qty_bd_wm)+sum(cur_qty_bd_ref)+sum(cur_qty_bd_dvd)+                                  \
			sum(cur_qty_bd_dva)+sum(cur_qty_bd_etc)+sum(cur_qty_bd_vc),'FM999,999,999') toatal_bd,       \
	 to_char(sum(cur_qty_sb_ctv)+sum(cur_qty_sb_rac)+sum(cur_qty_sb_mwo)+                                \
	 		sum(cur_qty_sb_wm)+sum(cur_qty_sb_ref)+sum(cur_qty_sb_dvd)+                                  \
			sum(cur_qty_sb_dva)+sum(cur_qty_sb_etc)+sum(cur_qty_sb_vc),'FM999,999,999') toatal_sb        \
from                                                                                                     \
(                                                                                                        \
select                                                                                                   \
     CASE WHEN xyz.dc_cd in ('BJZ','XAZ','SYZ','HEZ','JNZ','TJZ') then '华北'                          \
          WHEN xyz.dc_cd in ('SHZ','NJZ','HZZ') then '华东'                                           \
          ELSE '华南'	end group_cd,					                                                 \
	 xyz.dc_cd,                                                                                          \
	 uvw.dc_nm,                                                                                          \
	 to_char(sum(cur_qty_bd_ctv),'FM999,999,999') cur_qty_bd_ctv,                                        \
	 sum(cur_qty_sb_ctv) cur_qty_sb_ctv,                                                                 \
	 sum(cur_qty_bd_rac) cur_qty_bd_rac,                                                                 \
	 sum(cur_qty_sb_rac) cur_qty_sb_rac,                                                                 \
	 sum(cur_qty_BD_mwo) cur_qty_BD_mwo,                                                                 \
	 sum(cur_qty_sb_mwo) cur_qty_sb_mwo,                                                                 \
	 sum(cur_qty_bd_wm) cur_qty_bd_wm,                                                                   \
	 sum(cur_qty_sb_wm) cur_qty_sb_wm,                                                                   \
	 sum(cur_qty_bd_ref) cur_qty_bd_ref,                                                                 \
	 sum(cur_qty_sb_ref) cur_qty_sb_ref,                                                                 \
	 sum(cur_qty_bd_dvd) cur_qty_bd_dvd,                                                                 \
	 sum(cur_qty_sb_dvd) cur_qty_sb_dvd,                                                                 \
	 sum(cur_qty_bd_dva) cur_qty_bd_dva,                                                                 \
	 sum(cur_qty_sb_dva) cur_qty_sb_dva,                                                                 \
	 sum(cur_qty_bd_vc) cur_qty_bd_vc,                                                                   \
	 sum(cur_qty_sb_vc) cur_qty_sb_vc,                                                                   \
	 sum(cur_qty_bd_etc) cur_qty_bd_etc,                                                                 \
	 sum(cur_qty_sb_etc) cur_qty_sb_etc			                                                         \
from                                                                                                     \
(                                                                                                        \
select                                                                                                   \
 	zz.dc_cd,                                                                                            \
	decode(zz.l_class_cd,'CTV',decode(zz.stock_grade_type,'BD',zz.present_qty,0),0) cur_qty_bd_ctv,      \
	decode(zz.l_class_cd,'CTV',decode(zz.stock_grade_type,'SB',zz.present_qty,0),0) cur_qty_sb_ctv,      \
	decode(zz.l_class_cd,'RAC',decode(zz.stock_grade_type,'BD',zz.present_qty,0),0) cur_qty_bd_rac,      \
	decode(zz.l_class_cd,'RAC',decode(zz.stock_grade_type,'SB',zz.present_qty,0),0) cur_qty_sb_rac,      \
	decode(zz.l_class_cd,'MWO',decode(zz.stock_grade_type,'BD',zz.present_qty,0),0) cur_qty_BD_mwo,      \
	decode(zz.l_class_cd,'MWO',decode(zz.stock_grade_type,'SB',zz.present_qty,0),0) cur_qty_sb_mwo,      \
	decode(zz.l_class_cd,'W/M',decode(zz.stock_grade_type,'BD',zz.present_qty,0),0) cur_qty_bd_wm,       \
	decode(zz.l_class_cd,'W/M',decode(zz.stock_grade_type,'SB',zz.present_qty,0),0) cur_qty_sb_wm,       \
	decode(zz.l_class_cd,'REF',decode(zz.stock_grade_type,'BD',zz.present_qty,0),0) cur_qty_bd_ref,      \
	decode(zz.l_class_cd,'REF',decode(zz.stock_grade_type,'SB',zz.present_qty,0),0) cur_qty_sb_ref,      \
	decode(zz.l_class_cd,'DVD',decode(zz.stock_grade_type,'BD',zz.present_qty,0),0) cur_qty_bd_dvd,      \
	decode(zz.l_class_cd,'DVD',decode(zz.stock_grade_type,'SB',zz.present_qty,0),0) cur_qty_sb_dvd,      \
	decode(zz.l_class_cd,'DVA',decode(zz.stock_grade_type,'BD',zz.present_qty,0),0) cur_qty_bd_dva,      \
	decode(zz.l_class_cd,'DVA',decode(zz.stock_grade_type,'SB',zz.present_qty,0),0) cur_qty_sb_dva,      \
	decode(zz.l_class_cd,'V/C',decode(zz.stock_grade_type,'BD',zz.present_qty,0),0) cur_qty_bd_vc,       \
	decode(zz.l_class_cd,'V/C',decode(zz.stock_grade_type,'SB',zz.present_qty,0),0) cur_qty_sb_vc	,    \
	case when zz.l_class_cd  not in ('CTV','RAC','MWO','W/M','REF','DVD','DVA','V/C')                    \
			 then decode(zz.stock_grade_type,'BD',zz.present_qty,0) else 0 end  cur_qty_bd_etc,          \
	case when zz.l_class_cd  not in ('CTV','RAC','MWO','W/M','REF','DVD','DVA','V/C')                    \
			 then decode(zz.stock_grade_type,'SB',zz.present_qty,0) else 0 end  cur_qty_sb_etc           \
from (                                                                                                   \
select   xx.dc_cd,                                                                                       \
         yy.l_class_cd,                                                                                  \
				 xx.stock_grade_type,                                                                    \
				 sum(xx.present_qty) present_qty                                                         \
 from   			                                                                                     \
 (                                                                                                       \
  select  mm.dc_cd,                                                                                      \
        mm.corp_type,                                                                                    \
		mm.stock_owner_type,                                                                             \
	    mm.MODEL_CD,                                                                                     \
			mm.stock_grade_type,                                                                         \
        mm.sum_begin_mm_qty+nvl(dd.inout_qty,0) present_qty,                                             \
        mm.sum_begin_avail_qty_sb + nvl(dd.day_avail_qty_sb,0) avail_qty_sb                              \
    from                                                                                                 \
  (select a.dc_cd dc_cd,                                                                                 \
          a.corp_type corp_type,                                                                         \
		  a.stock_owner_type stock_owner_type,                                                           \
  		  a.MODEL_CD model_cd,                                                                           \
				a.stock_grade_type,                                                                      \
          sum(a.begin_mm_qty) sum_begin_mm_qty,                                                          \
          sum(a.begin_mm_qty - a.lm_norm_ord_not_shp_qty -                                               \
          a.lm_transfer_ord_not_shp_qty - a.lm_fact_rtn_ord_not_shp_qty -                                \
          nvl(a.lm_svc_rtn_ord_not_shp_qty,0) ) sum_begin_avail_qty_sb                                   \
    from  tb_ld_monstock a                                                                               \
   where  a.STOCK_YM=to_char(sysdate,'YYYYMM')	                                                         \
   group by 	a.dc_cd ,                                                                                \
   		 	a.corp_type ,                                                                                \
			a.stock_owner_TYPE ,                                                                         \
    		a.MODEL_CD,                                                                                  \
    		a.stock_grade_type                                                                           \
    ) mm,                                                                                                \
  (select B.dc_cd dc_cd,                                                                                 \
          B.corp_type corp_type,                                                                         \
		  B.stock_owner_type stock_owner_type,                                                           \
  		  B.MODEL_CD model_cd,                                                                           \
				b.stock_grade_type,                                                                      \
         sum(nvl(b.in_qty,0) - nvl(b.out_qty,0)) inout_qty,                                              \
         sum(nvl(b.in_qty,0) - nvl(b.ex_out_qty,0) -nvl(b.ord_qty,0)) day_avail_qty_sb                   \
    from vi_ld_daystock b                                                                                \
	where b.stock_ymd between to_char(sysdate,'YYYYMM')||'01' and to_char(sysdate,'YYYYMMDD')              \
	group by 	b.dc_cd ,                                                                                \
   		 	b.corp_type ,                                                                                \
			b.stock_owner_TYPE ,                                                                         \
    		b.MODEL_CD,                                                                                  \
    		b.stock_grade_type                                                                           \
   	 ) dd                                                                                                \
 where mm.dc_cd = dd.dc_cd(+)                                                                            \
 and      	mm.corp_type = dd.corp_type(+)                                                               \
 and		mm.stock_owner_type = dd.stock_owner_type(+)                                                 \
 and 		mm.MODEL_CD=dd.MODEL_CD(+)                                                                   \
 and        mm.stock_grade_type = dd.stock_grade_type(+)                                                 \
  ) xx,                                                                                                  \
tb_lm_model         yy                                                                                   \
where xx.corp_type = yy.corp_type                                                                        \
and xx.model_cd = yy.model_cd                                                                            \
and xx.stock_grade_type in ('BD','SB')                                                                   \
group by xx.dc_cd,                                                                                       \
	  yy.l_class_cd  ,                                                                                   \
		xx.stock_grade_type                                                                              \
) zz                                                                                                     \
 ) xyz ,                                                                                                 \
tb_lm_dc uvw                                                                                             \
where xyz.dc_cd = uvw.dc_cd                                                                              \
group by xyz.dc_cd ,uvw.dc_nm                                                                            \
) wokao                                                                                                  \
group by rollup(group_cd,dc_nm)" 

print "start query"

#print sqlstr
c.execute(sqlstr)


print "Describing test"

#print list(c.description)


c.arraysize = 20


print "start fetch"

r = c.fetchall()

#print r

mailbody = ""
mailbody = mailbody + ""
mailbody = mailbody + ""
mailbody = mailbody + ""
mailbody = mailbody + ""
#print r
i = 1
print "******************************"
print "start outer loop"
for x in r:
	j = 0
        if i == 1 :
		i =0 
                mailbody = mailbody + ""
        else:
                mailbody = mailbody + ""

        for y in x:
		j = j + 1
		if j in ( 1,2,4,6,8,10,12,14,16,18,20,22):
			if j in (1,2):
				mailbody = mailbody+ ""
			else:
                		mailbody = mailbody+""

		else:
			if j in ():
                                mailbody = mailbody+ ""
                        else:
                                mailbody = mailbody+""

mailbody = mailbody  + "
Gr.中心CTV_BDCTV_SBRAC_BDRAC_SBWMO_BDWMO_SBW/M_BDW/M_SBREF_BDREF_SBDVD_BDDVD_SBDVA_BDDVA_SBV/C_SBV/C_SBETC_BDETC_SBTOTAL_BDTOTAL_SB
"+y+""+str(y)+""+y+""+str(y)+"
" sqlstr = "select to_char(sysdate,'YYYY/MM/DD HH24:MI:SS') from dual" c.execute(sqlstr) r=c.fetchone() title = "BD and SB stock of " + str(r[0]) sqlstr = "select cd_nm from tb_lm_code where cd_type = 'C2' and use_yn = 'Y' and cd '*' " COMMASPACE = ',' c.execute(sqlstr) r=c.fetchall() tolist = ["han_huiwen at yahoo.com.cn"] for x in r: for y in x: fromaddr = "hhw_lb at sohu.com" toaddrs = "hanhw at lgcns.com.cn,jyoungkim at lgcns.com.cn" to = str(y) msg = MIMEText(mailbody,'html','gb2312') msg ['Subject'] = title msg ['From'] = 'CLIS SYSTEM' msg ['To'] = to server = smtplib.SMTP("officeplus.lgcns.com.cn") server.set_debuglevel(1) server.sendmail(fromaddr, to, msg.as_string()) #server.sendmail(fromaddr, toaddrs, msg.as_string()) server.quit() c.close() db.close() -------------- next part -------------- #!/usr/bin/ksh PATH=PATH=/usr/local/bin/ant_162/bin:/work/weblogic/bea/jdk131/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/home/logix/bin:/usr/bin/X11:/sbin:.:/usr/local/bin:/usr/vac/bin:/home/logix/util:/home/logix/Python-2.4.1:/db/app/oracle/product/8.1.7/bin:/usr/local/bin AUTHSTATE=compat CDPATH=.:/home/logix CVSROOT=:pserver:logix:logix at 156.147.165.87:/app/cvs/Repo CVS_HOME=/usr/local/bin DEFAULT_BROWSER=netscape EDITOR=vi ENV=/home/weblogic/.kshrc ERRNO=0 FCEDIT=/usr/bin/ed HOME=/home/logix JAVA_HOME=/work/weblogic/bea/jdk131 LANG=C LARCH_PATH=/usr/local/share/splint/lib LCLIMPORTDIR=/usr/local/share/splint/imports LC_ALL=C LC__FASTMSG=true LD_LIBRARY_PATH=/db/app/oracle/product/8.1.7/lib:/db/app/oracle/product/8.1.7/precomp/lib:/usr/lib LIBPATH=/db/app/oracle/product/8.1.7/lib:/db/app/oracle/product/8.1.7/precomp/lib::/usr/lib:/usr/dt/lib LINENO=1 LOCPATH=/usr/lib/nls/loc LOGIN=logix NLSPATH=/usr/lib/nls/msg/%L/%N:/usr/lib/nls/msg/%L/%N.cat NLS_LANG=American_America.US7ASCII ODMDIR=/etc/objrepos OPTIND=1 ORACLE_BASE=/db/app/oracle/ ORACLE_HOME=/db/app/oracle/product/8.1.7 ORACLE_SID=TMSDEV1 ORACLE_TERM=vt100 ORA_NLS33=/db/app/oracle/product/8.1.7/common/nls/admin/data PWD=/home/logix RANDOM=20417 SECONDS=1933 SHELL=/bin/ksh TERM=vt100 TERM_DEFAULT=lft TMOUT=0 TMP_DIR=/var/tmp TNS_ADMIN=/db/app/oracle/product/8.1.7/network/admin TZ=BEIST-8 USER=logix echo '************ start send email ************ '>>/tmp/tmssendmail.out echo $TNS_ADMIN echo $ORACLE_HOME tnsping TMSPROD_PROD >>/tmp/tmssendmail.out date >>/tmp/tmssendmail.out /home/logix/batch/sendMail.py >>/tmp/tmssendmail.log echo '############# end send mail ############'>>/tmp/tmssendmail.out

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年07月30日 星期六 23:15

limodou limodou at gmail.com
Sat Jul 30 23:15:33 HKT 2005

在 05-7-30,Schopendauer Nietzsche<mosquitoxh at yahoo.com.cn> 写道:
>  
> 
> hello  everyone:
> 
> I write a program using  dco2 by python,when i call this program  by 
> shell 
> 
> command,it's ok ,when I call this program by cron ,It errs.error 
> message 
> 
> as  flows:
> 
> Traceback (most recent call last):
>   File "/home/logix/batch/sendMail.py", line 14, in ?
>     db = DCOracle2.connect("lmusr/future2 at TMSPROD_PROD")
>   File "/home/logix/DCOracle2/DCOracle2/DCOracle2.py", line
> 189, in 
> connect
>     db = dco2.connect(u, p, dbname)
> dco2.DatabaseError: (12154, 'Error while trying to retrieve text for 
> error ORA-12154')

没有用过oracle,不过感觉是数据库访问错,它已经给出了错误码是"12154",建议你查一查错误码看一看是什么错误。会不会是程序的执行权限的问题。
> 
> can anyone help me solve this problem?  3ks
> 



-- 
I like python! 
My Donews Blog: http://www.donews.net/limodou
New Google Maillist: http://groups-beta.google.com/group/python-cn

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年07月31日 星期日 10:55

nicran nicran at gmail.com
Sun Jul 31 10:55:59 HKT 2005

another possible reason might be when running script with cron, the
environment variable isn't correct set by the cron shell, and it might
use another python such the one installed at /usr/bin

在 05-7-30,limodou<limodou at gmail.com> 写道:
> 在 05-7-30,Schopendauer Nietzsche<mosquitoxh at yahoo.com.cn> 写道:
> >
> >
> > hello  everyone:
> >
> > I write a program using  dco2 by python,when i call this program  by
> > shell
> >
> > command,it's ok ,when I call this program by cron ,It errs.error
> > message
> >
> > as  flows:
> >
> > Traceback (most recent call last):
> >   File "/home/logix/batch/sendMail.py", line 14, in ?
> >     db = DCOracle2.connect("lmusr/future2 at TMSPROD_PROD")
> >   File "/home/logix/DCOracle2/DCOracle2/DCOracle2.py", line
> > 189, in
> > connect
> >     db = dco2.connect(u, p, dbname)
> > dco2.DatabaseError: (12154, 'Error while trying to retrieve text for
> > error ORA-12154')
> 
> 没有用过oracle,不过感觉是数据库访问错,它已经给出了错误码是"12154",建议你查一查错误码看一看是什么错误。会不会是程序的执行权限的问题。
> >
> > can anyone help me solve this problem?  3ks
> >
> 
> 
> 
> --
> I like python!
> My Donews Blog: http://www.donews.net/limodou
> New Google Maillist: http://groups-beta.google.com/group/python-cn
> 
> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
> 
> 
>

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号