示例#1
0
def main(argv=None):
    if argv is None:
       argv = sys.argv
    
    opts, extraparams = getopt.gnu_getopt(argv[1:], "hvfmeu:", ["help", "--filter", "--more", '--exact', '--upper-bound='])
    
    verbose = False
    more_info = False
    filter = False
    filter_url =  u'http://aranzulla.tecnologia.virgilio.it/s/'
    upper_bound = 1000
    lower_bound = -1
    mode = 'BROAD'
    
    google = Google()
    
    for o, a in opts:
        if o == "-v":
            verbose = True
        elif o in ("-u", "--upper-bound"):
            upper_bound = int(a)
        elif o in ("-l", "--lower-bound"):
            lower_bound = int(a)
        elif o in ("-n", "--num-words"):
            num_words = int(a)
        elif o in ("-f", "--filter"):
            filter = True
        elif o in ("-h", "--help"):
            print __doc__
            sys.exit(0)
        elif o in ("-m", "--more"):
            more_info = True
        elif o in ("-e", "--exact"):
            mode = 'EXACT'
        else:
            assert False, "UnhandledOption"
                     
    for keyword in extraparams:
        km = KeywordManager(keyword)
        keywords = google.getAdwordsKeywords(keyword, mode)
        km.importStructuredKeywords(keyword, keywords)
        km.removeUncleanKeywords()
        if mode == 'BROAD':
            km.removeEqualGlobalsAndRegionals()
        km.sort('regional_score')
        
        if filter:
            print 'Computing filtered results...'
            doc = km.genXml(lower_bound, upper_bound, filter_url)
            f = codecs.open(os.path.join('output', keyword+'-filtered.xml'), 'w','utf-8')
            f.write(doc.toprettyxml(indent='  '))
            f.close()
        
        if not filter or (filter and more_info):
            print 'Computing results...'
            doc = km.genXml(lower_bound, upper_bound)
            f = codecs.open(os.path.join('output', keyword+'.xml'), 'w', 'utf-8')
            f.write(doc.toprettyxml(indent='  '))
            f.close()
        
        if more_info:
            #save everything
            f = codecs.open(os.path.join('output', keyword+'.txt'), 'w', 'utf-8')
            f.writelines([unicode(obj)+'\n' for obj in km.getKeywordEntries()])
            if filter:
                subprocess.Popen(['diff -Naru ' +os.path.join('output', keyword+'.xml')+ ' ' + os.path.join('output', keyword+'-filtered.xml') + ' > ' + os.path.join('output', keyword+'-filtered.diff') ], shell=True)
            f.close()            
        
    print 'Program terminates correctly'
    return 0
示例#2
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    opts, extraparams = getopt.gnu_getopt(
        argv[1:], "hvfmeu:",
        ["help", "--filter", "--more", '--exact', '--upper-bound='])

    verbose = False
    more_info = False
    filter = False
    filter_url = u'http://aranzulla.tecnologia.virgilio.it/s/'
    upper_bound = 1000
    lower_bound = -1
    mode = 'BROAD'

    google = Google()

    for o, a in opts:
        if o == "-v":
            verbose = True
        elif o in ("-u", "--upper-bound"):
            upper_bound = int(a)
        elif o in ("-l", "--lower-bound"):
            lower_bound = int(a)
        elif o in ("-n", "--num-words"):
            num_words = int(a)
        elif o in ("-f", "--filter"):
            filter = True
        elif o in ("-h", "--help"):
            print __doc__
            sys.exit(0)
        elif o in ("-m", "--more"):
            more_info = True
        elif o in ("-e", "--exact"):
            mode = 'EXACT'
        else:
            assert False, "UnhandledOption"

    for keyword in extraparams:
        km = KeywordManager(keyword)
        keywords = google.getAdwordsKeywords(keyword, mode)
        km.importStructuredKeywords(keyword, keywords)
        km.removeUncleanKeywords()
        if mode == 'BROAD':
            km.removeEqualGlobalsAndRegionals()
        km.sort('regional_score')

        if filter:
            print 'Computing filtered results...'
            doc = km.genXml(lower_bound, upper_bound, filter_url)
            f = codecs.open(os.path.join('output', keyword + '-filtered.xml'),
                            'w', 'utf-8')
            f.write(doc.toprettyxml(indent='  '))
            f.close()

        if not filter or (filter and more_info):
            print 'Computing results...'
            doc = km.genXml(lower_bound, upper_bound)
            f = codecs.open(os.path.join('output', keyword + '.xml'), 'w',
                            'utf-8')
            f.write(doc.toprettyxml(indent='  '))
            f.close()

        if more_info:
            #save everything
            f = codecs.open(os.path.join('output', keyword + '.txt'), 'w',
                            'utf-8')
            f.writelines(
                [unicode(obj) + '\n' for obj in km.getKeywordEntries()])
            if filter:
                subprocess.Popen([
                    'diff -Naru ' + os.path.join('output', keyword + '.xml') +
                    ' ' + os.path.join('output', keyword + '-filtered.xml') +
                    ' > ' + os.path.join('output', keyword + '-filtered.diff')
                ],
                                 shell=True)
            f.close()

    print 'Program terminates correctly'
    return 0
示例#3
0
def main(argv=None):
    if argv is None:
       argv = sys.argv
    
    opts, extraparams = getopt.gnu_getopt(argv[1:], "hvf", ["help", "--filter"])
    
    verbose = False
    more_info = False
    filter = False
    filter_url =  u'http://aranzulla.tecnologia.virgilio.it/s/'
    upper_bound = 1000
    lower_bound = -1
    num_words = 3
    
    google = Google()
    
    for o, a in opts:
        if o == "-v":
            verbose = True
        elif o in ("-u", "--upper-bound"):
            upper_bound = int(a)
        elif o in ("-l", "--lower-bound"):
            lower_bound = int(a)
        elif o in ("-n", "--num-words"):
            num_words = int(a)
        elif o in ("-f", "--filter"):
            filter = True
        elif o in ("-h", "--help"):
            print __doc__
            sys.exit(0)
        else:
            assert False, "UnhandledOption"
                     
    for keyword in extraparams:
        km = KeywordManager(keyword)
        keywords = google.getKeywords(keyword)
        km.importKeywords(keyword, keywords)
        #WARNING: do not filter for bannedchars for now
            
        print 'Computing results...'
        doc = km.genXml(lower_bound, upper_bound)
        f = codecs.open(os.path.join('output', keyword+'.xml'), 'w', 'utf-8')
        f.write(doc.toprettyxml(indent='  '))
        f.close()
        
        if filter:
            print 'Computing filtered results...'
            doc = km.genXml(lower_bound, upper_bound, filter_url)
            f = codecs.open(os.path.join('output', keyword+'-filtered.xml'), 'w','utf-8')
            f.write(doc.toprettyxml(indent='  '))
            f.close()
            #make diff
            subprocess.Popen(['diff -Naru ' +os.path.join('output', keyword+'.xml')+ ' ' + os.path.join('output', keyword+'-filtered.xml') + ' > ' + os.path.join('output', keyword+'-filtered.diff') ], shell=True)
        
        #save everything
        f = codecs.open(os.path.join('output', keyword+'.txt'), 'w', 'utf-8')
        if more_info:
            f.writelines([unicode(obj)+'\n' for obj in km.getKeywords()])
        else:
            f.writelines([unicode(obj.keyword)+'\n' for obj in km.getKeywordEntries()])
        f.close()            
        
    print 'Program terminates correctly'
    return 0
示例#4
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    opts, extraparams = getopt.gnu_getopt(argv[1:], "hvf",
                                          ["help", "--filter"])

    verbose = False
    more_info = False
    filter = False
    filter_url = u'http://aranzulla.tecnologia.virgilio.it/s/'
    upper_bound = 1000
    lower_bound = -1
    num_words = 3

    google = Google()

    for o, a in opts:
        if o == "-v":
            verbose = True
        elif o in ("-u", "--upper-bound"):
            upper_bound = int(a)
        elif o in ("-l", "--lower-bound"):
            lower_bound = int(a)
        elif o in ("-n", "--num-words"):
            num_words = int(a)
        elif o in ("-f", "--filter"):
            filter = True
        elif o in ("-h", "--help"):
            print __doc__
            sys.exit(0)
        else:
            assert False, "UnhandledOption"

    for keyword in extraparams:
        km = KeywordManager(keyword)
        keywords = google.getKeywords(keyword)
        km.importKeywords(keyword, keywords)
        #WARNING: do not filter for bannedchars for now

        print 'Computing results...'
        doc = km.genXml(lower_bound, upper_bound)
        f = codecs.open(os.path.join('output', keyword + '.xml'), 'w', 'utf-8')
        f.write(doc.toprettyxml(indent='  '))
        f.close()

        if filter:
            print 'Computing filtered results...'
            doc = km.genXml(lower_bound, upper_bound, filter_url)
            f = codecs.open(os.path.join('output', keyword + '-filtered.xml'),
                            'w', 'utf-8')
            f.write(doc.toprettyxml(indent='  '))
            f.close()
            #make diff
            subprocess.Popen([
                'diff -Naru ' + os.path.join('output', keyword + '.xml') +
                ' ' + os.path.join('output', keyword + '-filtered.xml') +
                ' > ' + os.path.join('output', keyword + '-filtered.diff')
            ],
                             shell=True)

        #save everything
        f = codecs.open(os.path.join('output', keyword + '.txt'), 'w', 'utf-8')
        if more_info:
            f.writelines([unicode(obj) + '\n' for obj in km.getKeywords()])
        else:
            f.writelines([
                unicode(obj.keyword) + '\n' for obj in km.getKeywordEntries()
            ])
        f.close()

    print 'Program terminates correctly'
    return 0