Beispiel #1
0
def main():


    # start QT UI
    sargv = sys.argv + ['--style', 'material']
    app = QApplication(sargv)
    font = QFont()
    font.setFamily("Ariel")

    app.setFont(font)
    # manually detect lid open close event from the start

    ui_view = QQuickView()
    
    ui_view.setSource(QUrl.fromLocalFile('RobotPanelSelect.qml'))
    ui_view.setWidth(800)
    ui_view.setHeight(480)
    ui_view.setMaximumHeight(480)
    ui_view.setMaximumWidth(800)
    ui_view.setMinimumHeight(480)
    ui_view.setMinimumWidth(800)
    # ui_view = UIController.get_ui()
    ui_view.show()

    ret = app.exec_()

    # Teminate
    sys.exit(ret)
Beispiel #2
0
def buildandsave(site, exit_on_save=True):
    agent = Agent(reactor)
    curator = User().get_by_role(site, keys.entity_twitter)

    leagues = []
    deferreds_league = []
    for l in curator[user_keys.user_site_leagues]:
        league = Entity().get_item(league=l, profile='league:' + l)
        d = agent.request(
            "HEAD",
            str('http://' + league[keys.entity_site] + '/tw/' +
                league[keys.entity_twitter_id] + '/avatar_large.png'))
        d.addCallback(add_redirect, league, leagues, 'large')
        deferreds_league.append(d)
    yield defer.DeferredList(deferreds_league)
    print 'leagues length:', len(leagues)

    players = []
    deferreds_small = []
    for p in Entity().query_2(index=Entity.index_site_profile,
                              site__eq=curator[user_keys.user_role],
                              query_filter={'twitter__null': False},
                              limit=200):
        d = agent.request(
            "HEAD",
            str('http://' + p[keys.entity_site] + '/tw/' +
                p[keys.entity_twitter_id] + '/avatar_small.png'))
        d.addCallback(add_redirect, p, players, 'small')
        deferreds_small.append(d)
    yield defer.DeferredList(deferreds_small)
    print 'players length:', len(players)

    view = QQuickView()
    view.setSource(QUrl('qml/render/curator_twitter_bg.qml'))
    view.rootObject().setProperty('bgcolor', 'black')
    view.setWidth(1500)
    view.setHeight(500)
    view.show()
    view.rootObject().setProperty('curator', curator._data)
    view.rootObject().setProperty('leagues', leagues)
    view.rootObject().setProperty('players', players)

    yield task.deferLater(reactor, 30, screenshot, view, site, curator)
    if exit_on_save:
        print 'exit on save'
        reactor.callLater(0, reactor.stop)
    else:
        print 'done'
Beispiel #3
0
def buildandsave(league_name, exit_on_save=True):
    try:
        agent = Agent(reactor)
        league_user = User().get_by_role(league_name, keys.entity_twitter)
        print 'league_user:'******'team:',
                                  query_filter={
                                      'twitter__null': False,
                                      'twitter_id__null': False
                                  }):
            d = agent.request(
                "HEAD",
                str('http://' + t[keys.entity_site] + '/tw/' +
                    t[keys.entity_twitter_id] + '/avatar_large.png'))
            d.addCallback(add_redirect, t, teams, 'large')
            deferreds_team.append(d)
        yield defer.DeferredList(deferreds_team)

        players = []
        deferreds_small = []
        for p in Entity().query_2(league__eq=sys.argv[1],
                                  profile__beginswith='http:',
                                  query_filter={
                                      'twitter__null': False,
                                      'twitter_id__null': False
                                  },
                                  limit=300):
            d = agent.request(
                "HEAD",
                str('http://' + p[keys.entity_site] + '/tw/' +
                    p[keys.entity_twitter_id] + '/avatar_small.png'))
            d.addCallback(add_redirect, p, players, 'small')
            deferreds_small.append(d)
        yield defer.DeferredList(deferreds_small)
        print 'players length:', len(players)

        view = QQuickView()
        view.setSource(QUrl('qml/render/league_twitter_bg.qml'))
        view.setWidth(1500)
        view.setHeight(500)
        view.show()

        try:
            view.rootObject().setProperty(
                'bgcolor', '#' + league_user[keys.entity_colors][0])
        except:
            view.rootObject().setProperty('bgcolor', '#000000')
        view.rootObject().setProperty('league', league)
        view.rootObject().setProperty('players', players)
        view.rootObject().setProperty('teams', teams)

        yield task.deferLater(reactor, 30, screenshot, view, league_user)
        if exit_on_save:
            print 'exit on save'
            reactor.callLater(0, reactor.stop)
        else:
            print 'done'
    except Exception as e:
        print 'build and save exception:', e
Beispiel #4
0
def run_charts():
    print 'run charts'
    gsi = Tweet().describe()['Table']['GlobalSecondaryIndexes']
    oil = [g for g in gsi
           if g['IndexName'] == Tweet.index_league][0]['ProvisionedThroughput']
    oil = {
        Tweet.index_league: {
            'read': oil['ReadCapacityUnits'],
            'write': oil['WriteCapacityUnits']
        }
    }
    nil = copy.deepcopy(oil)
    nil[Tweet.index_league]['read'] = 200
    oil[Tweet.index_league]['read'] = 20
    try:
        print 'increate throughput:', nil
        Tweet().update_global_secondary_index(global_indexes=nil)
    except Exception as e:
        print 'increase exception:', e
    yield task.deferLater(reactor, 15, defer.succeed, True)
    for u in User().scan(role__contains='.com', twitter_apps__null=False):
        try:
            site = u[user_keys.user_role]
            chart_tweet = tweets.chart_tweet(u, 'Last 24 Hours')
            print 'chart tweet:', chart_tweet
            yield task.deferLater(reactor, 1, defer.succeed, True)
            print 'site:', site
            if not u[keys.entity_description]:
                u[keys.entity_description] = 'placeholder'
                u.partial_save()

            yesterday = int(time.time()) - (24 * 60 * 60)
            yesterday = str(yesterday * 1000)

            curator = User().get_by_role(site, keys.entity_twitter)
            charts = []

            categories = list(curator[user_keys.user_site_leagues])
            for c in categories:
                #tc = SocialBeta().query_count(SocialBeta.index_social_ts_received, league__eq=c, social_ts_received__gt=yesterday, query_filter={'social_act__eq': 'tweet'})
                tweet_filter = {
                    'known_retweet__null': True,
                    'unknown_retweet__null': True,
                    '_ts_ms__gt': yesterday
                }

                tc = Tweet().query_count(index=Tweet.index_league,
                                         league__eq=c,
                                         query_filter=tweet_filter,
                                         scan_index_forward=False)

                known_retweet_filter = {
                    'known_retweet__null': False,
                    '_ts_ms__gt': yesterday
                }
                krc = Tweet().query_count(index=Tweet.index_league,
                                          league__eq=c,
                                          query_filter=known_retweet_filter,
                                          scan_index_forward=False)

                unknown_retweet_filter = {
                    'unknown_retweet__null': False,
                    '_ts_ms__gt': yesterday
                }
                urc = Tweet().query_count(index=Tweet.index_league,
                                          league__eq=c,
                                          query_filter=unknown_retweet_filter,
                                          scan_index_forward=False)

                conversion_filter = {
                    'known_conversation__null': False,
                    '_ts_ms__gt': yesterday
                }
                cc = Tweet().query_count(index=Tweet.index_league,
                                         league__eq=c,
                                         query_filter=conversion_filter,
                                         scan_index_forward=False)
                ce = {c: (tc, krc, urc, cc)}
                print ce
                charts.append(ce)

            charts.sort(key=lambda x: x[x.keys()[0]][0])

            tweets_list = [t[t.keys()[0]][0] for t in charts]
            known_retweets_list = [t[t.keys()[0]][1] for t in charts]
            unknown_retweets_list = [t[t.keys()[0]][2] for t in charts]
            conversations_list = [t[t.keys()[0]][3] for t in charts]
            categories = [t.keys()[0] for t in charts]

            height = 200 + (40 * len(categories))

            view = QQuickView()
            view.setSource(QUrl('qml/render/chart_daily.qml'))
            view.setWidth(800)
            view.setHeight(height)

            view.rootObject().setProperty('categories', categories)
            view.rootObject().setProperty('_height', height)
            view.rootObject().setProperty(
                'title', 'Tweets/Retweets/Conversations - ' + site)
            view.rootObject().setProperty('description',
                                          u[keys.entity_description])
            view.rootObject().setProperty('conversations', conversations_list)
            view.rootObject().setProperty('retweets', known_retweets_list)
            view.rootObject().setProperty('unknown_retweets',
                                          unknown_retweets_list)
            view.rootObject().setProperty('tweets', tweets_list)

            view.show()
            yield task.deferLater(reactor, 5, defer.succeed, True)
            img = view.grabWindow()
            chart_location = '/home/ubuntu/Desktop/' + site + '.png'
            res = img.save(chart_location)
            print 'save result:', res
            yield task.deferLater(reactor, 5, defer.succeed, True)
            restful.post_tweet(u, u, chart_tweet, chart_location)
            yield task.deferLater(reactor, 15, defer.succeed, True)
            os.remove(chart_location)
            view.deleteLater()

        except Exception as e:
            print 'chart exception:', e
    try:
        print 'decreate throughput:', oil
        Tweet().update_global_secondary_index(global_indexes=oil)
    except Exception as e:
        print 'descrease exception:', e
    yield task.deferLater(reactor, 15, defer.succeed, True)
    reactor.callLater(0, reactor.stop)
#Sample Python File
from PyQt5.QtCore import QUrl
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtQuick import QQuickView

if __name__ == '__main__':
    import os
    import sys

    app = QGuiApplication(sys.argv)

    view = QQuickView()
    view.setWidth(500)
    view.setHeight(500)
    view.setTitle('Hello PyQt')
    view.setResizeMode(QQuickView.SizeRootObjectToView)
    view.setSource(QUrl.fromLocalFile(os.path.join(os.path.dirname(__file__),'main.qml')))

    view.show()
    qml_rectangle = view.rootObject()

    sys.exit(app.exec_())
Beispiel #6
0
    
players = []     
for p in Entity().query_2(league__eq=sys.argv[1], profile__beginswith='http:', query_filter={ 'twitter__null': False}, limit=400):
    players.append(p._data)
'''

from PyQt5.QtQuick import QQuickView
from PyQt5.QtCore import QUrl

view = QQuickView()
view.setSource(QUrl('qml/render/twitter_avatar.qml'))
#view.rootObject().setProperty('bgcolor', '#' + league_user[keys.entity_colors][0])
view.rootObject().setProperty('league', league)
#view.rootObject().setProperty('players', players)
view.rootObject().setProperty('cards', cards)
view.setWidth(400)
view.setHeight(400)
view.show()
print view.rootObject()

from twisted.internet import task, reactor, defer


def backup():
    view.rootObject().setProperty('backup', True)
    league_backup = UserAvailable().get_by_role(sys.argv[1],
                                                keys.entity_twitter)
    if league_backup:
        img = view.grabWindow()
        il = '/home/ubuntu/Desktop/avatar_' + sys.argv[1] + '_backup.png'
        res = img.save(il)
Beispiel #7
0
from PyQt5.QtCore import QUrl, QObject, pyqtSlot, pyqtSignal
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtQuick import QQuickView
import mnistMethod

path = 'mainWindow.qml'
app = QGuiApplication([])
view = QQuickView()
view.engine().quit.connect(app.quit)
view.setHeight(700)
view.setWidth(1200)
view.setSource(QUrl(path))
view.show()

context = view.rootContext()
root = view.rootObject()

context.setContextProperty("mnistHandler", mnistMethod.mnistHandler)

app.exec_()
Beispiel #8
0
def qt_avatar(avi=None, prefix='/tmp'):
    print 'new avatar:', avi[keys.entity_twitter], 'twitter id:', avi[
        keys.entity_twitter_id]
    meta = {}
    curator = User().get_curator(avi[keys.entity_league])
    previous = None
    try:
        avis = s3.get_twitter_media(avi, 'large')
        count = str(len(avis))
        current = fixed.key_url(avis[0])
        previous = fixed.key_url(avis[1])
    except Exception as e:
        print e
    print current, 'count:', count, 'previous:', previous
    bgcolor = 'black'
    local_font = 'http://socialcss.com/Roboto-Regular.ttf?raw=true'
    site = curator[user_keys.user_role]

    friends = []
    try:
        ls = ProfileTwitter().profile_last(avi[keys.entity_twitter_id])
        meta.update(ls._data)
        print 'has recent:', fixed.days_since(ls,
                                              time_keys.ts_add) if ls else None
        if ls[ProfileTwitter.profile_background_color]:
            bgcolor = '#' + ls[ProfileTwitter.profile_background_color]
            print 'colors background:', bgcolor, 'link profile:', ls[
                'profile_link_color']
        for f in list(ls[twitter_keys.league_follows(
                avi[keys.entity_league])].intersection(
                    ls[twitter_keys.league_mutual(avi[keys.entity_league])])):
            friends.append(f)
        print 'friend:', friends
    except Exception as e:
        print 'avatar exception:', e

    meta.update(avi)

    view = QQuickView()
    view.setSource(QUrl('qml/render/avi_update.qml'))
    view.show()

    view.setWidth(590)
    view.rootObject().setProperty('current', current)
    if previous:
        view.rootObject().setProperty('previous', previous)
    view.rootObject().setProperty('bgcolor', bgcolor)
    view.rootObject().setProperty('font', local_font)
    view.rootObject().setProperty('site', site)
    view.rootObject().setProperty('count', count)
    view.rootObject().setProperty('league', avi[keys.entity_league])
    view.rootObject().setProperty('twitter', avi[keys.entity_twitter])
    if friends:
        view.setHeight(380)
        view.rootObject().setProperty('friends', json.dumps(friends))
    else:
        view.setHeight(280)

    local_file_name = prefix + '/avi_update_' + avi[
        keys.entity_twitter] + '.png'
    print 'local_file_name:', local_file_name

    def tick():
        try:
            upload_png = avi[keys.entity_league] + '/tweet/' + str(
                int(time.time())) + '.png'
            img = view.grabWindow()
            print 'img:', img, local_file_name, img.isNull()
            render_res = img.save(local_file_name)
            print 'render_res:', render_res, 'file name:', upload_png, 'tweet:', avi
            if render_res and avi and twitter_keys.message_tweet in avi:
                b = s3.bucket_straight(curator['role'])
                s3.save_s3(b, upload_png, None, local_file_name, 'image/png',
                           'public-read', meta)
                if avi:

                    avi[twitter_keys.
                        message_pic] = 'http://' + b.name + '/' + upload_png
                    print 'append to tweet:', avi[
                        twitter_keys.message_tweet], 'url:', avi[
                            twitter_keys.message_pic]
                    TweetQueue().createMessage(avi)
            else:
                print 'skip publish'
        except Exception as e:
            print 'tick exception:', e
        reactor.callLater(0, reactor.stop)

    QTimer.singleShot(15000, tick)
Beispiel #9
0
from PyQt5.QtQuick import QQuickView
from PyQt5.QtCore import QUrl

avi_property = []
for e in Entity().query_2(index=Entity.index_team_profile,
                          team__eq=sys.argv[1],
                          query_filter={'twitter__null': False}):
    print e._data
    avi_property.append(e._data)

print avi_property

view = QQuickView()
view.setSource(QUrl('qml/render/avi_team.qml'))
view.setWidth(590)
view.setHeight(360)
view.rootObject().setProperty('avis',
                              json.dumps(avi_property, cls=fixed.SetEncoder))
view.show()
print view.rootObject()


def screenshot():
    img = view.grabWindow()
    res = img.save('/home/ubuntu/Desktop/test.png')
    #res = img.save('/home/ubuntu/Desktop/avi_' + sys.argv[2] + '.png')
    print 'save result:', res


#img = view.rootObject().grabToImage()