Ejemplo n.º 1
0
# setup file to get uid and start weibo id
setup_file = 'setup.txt' 
copy_file = file_address + '\copy\setup.txt'

#get on server mongodbmain
client = MongoClient('54.223.178.198', 27110)
db = client['weibo-database']
collection = db['weibo-collection']

#check the total number of uid
f = open(setup_file, 'r')
a = f.readlines()
Total_number = len(a)
f.close()

weibo_scrapy = Weibo(url, '')
#Scrapy Sina
while True:
    for n_count in xrange(Total_number):
        f = open(setup_file, 'r')
        a = f.readlines()
        Total_number = len(a)
        f.close()
        list_id_time = []
        
        for n_dummy in xrange(Total_number):
            list_id_time.append(a[n_dummy].split())
            if (len(list_id_time[n_dummy]) ==1):
                list_id_time[n_dummy].append(' ')
        
        f = open(copy_file,'w')
        for item in xrange(len(self.hour_num)-24,len(self.hour_num)):
            plt.bar(item-len(self.hour_num)+24, self.hour_num[item])
            plt.axis([0,24,0,max(self.hour_num)])
        plt.show()
        
        for item in xrange(len(self.day_num)):
            begin_day = int(self.day_dict[0])
            plt.bar(item+begin_day, self.day_num[item])
            plt.axis([int(self.day_dict[0]),int(self.day_dict[-1]), 0, max(self.day_num)])
        plt.show()
        
if __name__ =="__main__":

    uid = '2041499443' 
    url = 'http://weibo.cn/'
    file_address = os.path.dirname(os.path.abspath(__file__))
    
    weibo_scrapy = Weibo(url,uid)
    weibo_scrapy.request_check(weibo_scrapy.home_url)
    weibo_scrapy.get_name()
    weibo_scrapy.search_statuses(u'武汉 下雨')
    
    
    weibo_file = u"search武汉 下雨"    
    search_path = file_address + '\\result\\' + weibo_file
    keyword_object = Keyword_Frequency(search_path)
    
    keyword_object.Get_Text()