[Python]
# Coding = gbk
Import OS
Import sys
Import argparse
Import commands
Import logging
Status, username = commands. getstatusoutput ('whoam ')
Logging. basicConfig (level = logging. DEBUG,
Format = username + '% (asctime) s % (filename) s [line: % (lineno) d] % (levelname) s % (message) s ',
Datefmt = '% Y-% m-% d % H: % M: % s ',
Filename = '. log' + _ file __,
Filemode = 'A ')
Def perror_and_exit (message, status =-1 ):
Sys. stderr. write (message + '\ n ')
Logging.info (message + 'sys exit ')
Sys. exit (status)
Count = 0
Def handle_keywords (userid, keywords, fw ):
Global count
Count + = 1
Pass
If _ name _ = "_ main __":
Directory = "/home/junfeng"
If len (sys. argv )! = 2:
Perror_and_exit ("Usage: python % s keyword or idea" % (_ file _ + ""))
If sys. argv [1] = "keyword ":
Filename = OS. path. join (directory, "userid_showword.active.tradeid5401.20130329.txt ")
Print filename
Fw = file ("userid_showwords_brand.txt", "w ")
Last_userid = None
Keywords = []
For line in file (filename ):
Line = line. strip (). split ()
Userid = line [0]
Keyword = line [1]
If userid = last_userid:
Keywords. append (keyword)
Else:
If len (keywords)> 0:
Handle_keywords (last_userid, keywords, fw)
Pass
Last_userid = userid
Keywords = [keyword]
Handle_keywords (last_userid, keywords, fw)
Print keywords
Global count
Print count
Pass
Elif sys. argv [1] = "idea ":
Filename = OS. path. join (directory, "userid_title_desc1_desc2.active.tradeid5401.20130329.txt ")
For line in file (filename ):
Line = line. strip (). split ()
Pass
# Coding = gbk
Import OS
Import sys
Import argparse
Import commands
Import logging
Status, username = commands. getstatusoutput ('whoam ')
Logging. basicConfig (level = logging. DEBUG,
Format = username + '% (asctime) s % (filename) s [line: % (lineno) d] % (levelname) s % (message) s ',
Datefmt = '% Y-% m-% d % H: % M: % s ',
Filename = '. log' + _ file __,
Filemode = 'A ')
Def perror_and_exit (message, status =-1 ):
Sys. stderr. write (message + '\ n ')
Logging.info (message + 'sys exit ')
Sys. exit (status)
Count = 0
Def handle_keywords (userid, keywords, fw ):
Global count
Count + = 1
Pass
If _ name _ = "_ main __":
Directory = "/home/junfeng"
If len (sys. argv )! = 2:
Perror_and_exit ("Usage: python % s keyword or idea" % (_ file _ + ""))
If sys. argv [1] = "keyword ":
Filename = OS. path. join (directory, "userid_showword.active.tradeid5401.20130329.txt ")
Print filename
Fw = file ("userid_showwords_brand.txt", "w ")
Last_userid = None
Keywords = []
For line in file (filename ):
Line = line. strip (). split ()
Userid = line [0]
Keyword = line [1]
If userid = last_userid:
Keywords. append (keyword)
Else:
If len (keywords)> 0:
Handle_keywords (last_userid, keywords, fw)
Pass
Last_userid = userid
Keywords = [keyword]
Handle_keywords (last_userid, keywords, fw)
Print keywords
Global count
Print count
Pass
Elif sys. argv [1] = "idea ":
Filename = OS. path. join (directory, "userid_title_desc1_desc2.active.tradeid5401.20130329.txt ")
For line in file (filename ):
Line = line. strip (). split ()
Pass