Exemplo n.º 1
0
def CreateVideoMessage(oriYear, obj):
    duh = dbUsersHelper()
    ip, port = duh.getNasHostIPPort()
    account, pwd = duh.getNasLoginAccountPwd()

    by = datetime.now().year - oriYear
    msg = str(by) + ' years ago' if by > 1 else str(by) + ' year ago'
    #picURI = obj['THUMBNAIL']
    basename = os.path.basename(obj['DIR'])
    msg = msg + "\n" + basename + "/" + obj['FILE_NAME']

    if ip and port and account and pwd:
        vph = VideoPlayerHelper(ip, port, account, pwd)
        url = vph.getVideoViewUrl(obj['DIR'], obj['FILE_NAME'])
        #print(url)
        msg = msg + "\n\n 影片: " + url

    return msg
Exemplo n.º 2
0
def CreatePhotoMessage(oriYear, obj):
    dbh = dbPhotoHelper()
    duh = dbUsersHelper()
    apiKey = duh.getGoogleAPIKey()
    geoh = None
    if apiKey:
        geoh = GeoHelper(apiKey)

    by = datetime.now().year - oriYear
    msg = str(by) + ' years ago' if by > 1 else str(by) + ' year ago'
    #picURI = obj['THUMBNAIL']
    basename = os.path.basename(obj['DIR'])
    msg = msg + "\n" + basename + "/" + obj['FILE_NAME']
    gps_address = obj['GPS_ADDRESS']
    gps = obj['GPS']
    if gps_address:
        msg = msg + "\n" + gps_address
    elif gps:
        if geoh:
            address = geoh.getNearAddress(gps)
            if address:
                msg = msg + "\n" + address
                dbh.UpdateGeoAddress(obj['FILE_NAME'], obj['DIR'], address)
    return msg
Exemplo n.º 3
0
def SetBotToken(token):   
    duh = dbUsersHelper()
    duh.setTelegramBotAccessToken(token)    
Exemplo n.º 4
0
def Push(users, memoryDate, randomPhotoNumbers):
    """
        Integrate all the processes.
        1. Get care list.
        2. GetManyYearPhotoDates
        3. GetPhotosByPhotoDates
        4. GetPhotoThumbnail
        5. Use google map api to find address which the photo taken with the data from photo exif gps information
        6. Use Line notify to remind you and enjoy it.
    """

    #memoryDate = datetime.today()
    duh = dbUsersHelper()
    #users = duh.getSMSUsers()
    #users = duh.getSMSUser(userId)
    noticeUsers = map(lambda user: (user, duh.getUserNotice(user['USER_ID'])),
                      users)
    print(memoryDate)
    photoDates = list(GetManyYearPhotoDates(memoryDate))

    for noticeUser in noticeUsers:
        catalogs = list(map(lambda data: data['NOTICE_USER_ID'],
                            noticeUser[1]))
        user = noticeUser[0]

        #photoFileNames=[]
        #photoThumbnails=[]
        #photoDates = GetManyYearPhotoDates(memoryDate,catalogs)
        photoFileNames = (GetPhotosByPhotoDates(photoDates, catalogs,
                                                randomPhotoNumbers))
        photoThumbnails = (GetPhotosThumbnail(photoFileNames))

        videoFileNames = GetVideosByVideoDates(photoDates, catalogs,
                                               randomPhotoNumbers)
        videoThumbnails = (GetVideosThumbnail(videoFileNames))

        print(user['USER_ID'] + ' ' + user['SMS_TYPE'])
        print(catalogs)

        PhotoMessage = []
        VideoMessage = []

        for data in photoThumbnails:
            for obj in data[1]:
                photoMsg = CreatePhotoMessage(data[0].year, obj)
                picURI = obj['THUMBNAIL']
                if picURI:
                    print(picURI)
                    PhotoMessage.append({
                        'year': data[0].year,
                        'msg': str(photoMsg),
                        'uri': picURI
                    })
                    #statusCode = line.send(str(photoMsg),picURI)
                    #print(statusCode)
        for data in videoThumbnails:
            for obj in data[1]:
                videoMsg = CreateVideoMessage(data[0].year, obj)
                picURI = obj['THUMBNAIL']
                if picURI:
                    print(picURI)
                    VideoMessage.append({
                        'year': data[0].year,
                        'msg': str(videoMsg),
                        'uri': picURI
                    })
                    #statusCode = line.send(str(videoMsg),picURI)
                    #print(statusCode)

        token = user['SMS_ID']
        if user['SMS_TYPE'] == SMSType.LineNotify.value:
            line = LineNotify(token)
            for p in PhotoMessage:
                line.send(p['msg'], p['uri'])
            for v in VideoMessage:
                line.send(v['msg'], v['uri'])
        elif user['SMS_TYPE'] == SMSType.TelegramBot.value:
            botToken = duh.getTelegramBotAccessToken()
            if not botToken:
                print(
                    'Must set telegram bot access token. Please type \'python SetBotToken.py [ACCESS_TOKEN]\''
                )
                continue
            bot = TelegramBot(botToken, token)

            for key, groups in groupby(PhotoMessage,
                                       lambda photo: photo['year']):
                gPhoto = list(groups)
                if len(gPhoto) <= 1:
                    bot.sendPhoto(gPhoto[0]['uri'], gPhoto[0]['msg'])
                else:
                    gPhotos = []
                    for g in gPhoto:
                        gPhotos.append(
                            TelegramBotMedia(TelegramMediaType.Photo, g['uri'],
                                             g['msg']))
                    r = bot.sendMediaGroup(gPhotos)
                    #print(r)

            for v in VideoMessage:
                #bot.sendText(v['msg'])
                bot.sendPhoto(v['uri'], v['msg'])
Exemplo n.º 5
0
def SetUserData(meta):
    duh = dbUsersHelper()
    duh.setUserData(meta)
Exemplo n.º 6
0
def SetCareCatagory(meta):
    duh = dbUsersHelper()
    duh.setCareCatagory(meta)
Exemplo n.º 7
0
def SetGoogleMapApi(apiKey):
    duh = dbUsersHelper()
    duh.setGoogleAPIKey(apiKey)
def SetNasLoginAccountPwd(account, pwd):
    duh = dbUsersHelper()
    duh.setNasLoginAccountPwd(account, pwd)
Exemplo n.º 9
0
def SetNasHostIPPort(ip,port):   
    duh = dbUsersHelper()
    duh.setNasHostIPPort(ip,port)    
Exemplo n.º 10
0
# -*- coding: UTF-8 -*-
from datetime import datetime
from db.SaUsersDB import dbUsersHelper
import mysys.PushPhoto as PhotoService

if __name__ == "__main__":
    duh = dbUsersHelper()
    users = duh.getSMSUsers()
    PhotoService.Push(users, datetime.today(), 3)