예제 #1
0
 def GetItemToSend(self):
     KeyList=r.hkeys('queue')
     for i in range(len(KeyList)):
         ToBeSendTitle=r.hget('queue',KeyList[i])
         ToBeSendImage=r.hget('img',KeyList[i])
         r.zadd('queuenumber',ToBeSendTitle,i)
         r.hset('imgkey',ToBeSendTitle,ToBeSendImage)
예제 #2
0
 def SaveRecentChanges(self):
     #self.FilterValid()
     #self.cache=filter(GetImage,self.cache)
     self.FamiliarItemForbidden()
     for i in range(len(self.cache)):
         itemkey=MU_MainConfig.EDITEDPREFIX+self.cache[i]
         r.hset('queue',itemkey,self.cache[i])
         timenow=time.time()
         r.zadd('expire',itemkey,timenow)
예제 #3
0
 def SaveRecentChanges(self):
     self.FilterValid()
     for item in self.cache:
         flag=GetImage(item)
         if flag==True:
             itemkey=EDITEDPREFIX+item
             r.hset('queue',itemkey,item)
             timenow=time.time()
             r.zadd('expire',itemkey,timenow)
         else:
             pass
예제 #4
0
 def PostItem(self):
     Keys=r.hkeys('queue')
     ReadyToPostItem=r.hget('queue',Keys[0])
     UnPushed=ForbiddenItemPushed(ReadyToPostItem)
     print UnPushed
     if UnPushed is not False:
         Image='imgcache/'+r.hget('img',EDITEDPREFIX+ReadyToPostItem)
         post(status=ReadyToPostItem,pic=Image)
         r.zrem('queuenumber',ReadyToPostItem)
         r.hdel('imgkey',EDITEDPREFIX+ReadyToPostItem)
         r.hdel('queue',EDITEDPREFIX+ReadyToPostItem)
         r.hset('queue',PUSHEDPREFIX+ReadyToPostItem,ReadyToPostItem)
     else:
         pass
예제 #5
0
 def PostItem(self):
     Keys=r.zrange('queuenumber',0,-1)
     ReadyToPostItem=Keys[0]
     UnPushed=ForbiddenItemPushed(ReadyToPostItem)
     if UnPushed is not False:
         name=r.hget('img',MU_MainConfig.EDITEDPREFIX+ReadyToPostItem)
         post(ReadyToPostItem,name)
         r.hdel('queue',MU_MainConfig.EDITEDPREFIX+ReadyToPostItem)
         os.remove('../imgcache/'+name)
         r.hdel('img',MU_MainConfig.EDITEDPREFIX+ReadyToPostItem)
         r.hdel('imgkey',MU_MainConfig.EDITEDPREFIX+ReadyToPostItem)
         score=r.zscore('queuenumber',ReadyToPostItem)
         r.zrem('queuenumber',ReadyToPostItem)
         scorequeue=r.zrange('queuenumber',int(score)-1,-1)
         for i in range(len(scorequeue)):
             score=r.zscore('queuenumber',scorequeue[i])
             r.zadd('queuenumber',scorequeue[i],score-1)
         r.hset('queue',MU_MainConfig.PUSHEDPREFIX+ReadyToPostItem,ReadyToPostItem)
     else:
         pass
예제 #6
0
 def GetItemToSend(self):
     scorequeue=r.zrevrange('queuenumber',0,-1)
     try:
         lastnumber=r.zscore('queuenumber',scorequeue[0])
         for i in range(len(self.cache)):
             scorequeue=r.zrevrange('queuenumber',0,-1)
             lastnumber=r.zscore('queuenumber',scorequeue[0])
             ToBeSendTitle=r.hget('queue',MU_MainConfig.EDITEDPREFIX+self.cache[i])
             ToBeSendImage=r.hget('img',MU_MainConfig.EDITEDPREFIX+self.cache[i])
             if ToBeSendTitle not in scorequeue:
                 r.zadd('queuenumber',ToBeSendTitle,lastnumber)
                 r.zincrby('queuenumber',ToBeSendTitle,1)
             r.hset('imgkey',ToBeSendTitle,ToBeSendImage)
     except:
         for i in range(len(self.cache)):
             ToBeSendTitle=r.hget('queue',MU_MainConfig.EDITEDPREFIX+self.cache[i])
             ToBeSendImage=r.hget('img',MU_MainConfig.EDITEDPREFIX+self.cache[i])
             r.zadd('queuenumber',ToBeSendTitle,i)
             r.zincrby('queuenumber',ToBeSendTitle,1)
             r.hset('imgkey',ToBeSendTitle,ToBeSendImage)        
예제 #7
0
def GetImage(title):
    try:
        url="http://zh.moegirl.org/"+title
        f=urllib.urlopen(url)
    except:
        return None
    src=f.read()
    f.close
    ssrc=BeautifulSoup(src,"html.parser")
    try:
        image_div=ssrc.find_all('a',class_='image')
        for i in range(len(image_div)):
            imgtag=image_div[i].find('img')
            if (int(imgtag['width']) > 200 and int(imgtag['height']) > 100): #出问题都是anna的锅
                img = imgtag['src']
                break
            else:
                continue
    except:
        return None
    isExists=os.path.exists('imgcache')
    if not isExists:
        os.makedirs('imgcache')
    name=unique_str()
    TheImageIsReadyToPush=False
    if locals().has_key("img"):
        try:
            with open('imgcache/'+name,'wb') as f:
                con=urllib.urlopen("http:"+img)
                f.write(con.read())
                f.flush()
                TheImageIsReadyToPush=True
                r.hset('img',EDITEDPREFIX+title,name)
        except BaseException, e:
                log.debug(e)
                return None
예제 #8
0
def GetImage(title):
    try:
        url="https://zh.moegirl.org/"+title
        f=urllib.urlopen(url)
    except:
        return None
    src=f.read()
    f.close
    ssrc=BeautifulSoup(src,"html.parser")
    try:
        image_div=ssrc.find_all('a',class_='image')
        for i in range(len(image_div)):
            imgtag=image_div[i].find('img')
            if (int(imgtag['width']) > 200 and int(imgtag['height']) > 100): #出问题都是anna的锅
                img = imgtag['src']
                break
            else:
                continue
    except:
        return None
    isExists=os.path.exists('../imgcache')
    if not isExists:
        os.makedirs('../imgcache')
    name=unique_str()
    TheImageIsReadyToPush=False
    if locals().has_key("img"):
        try:
            with open('../imgcache/'+name,'wb') as f:
                con=urllib.urlopen(img)
                f.write(con.read())
                f.flush()
                TheImageIsReadyToPush=True
                r.hset('img',MU_MainConfig.EDITEDPREFIX+title,name)
        except BaseException, e:
                log.debug(e)
                return None