Beispiel #1
0
    def HTMLChanges(self):
        cherrypy.response.headers["Content-Type"] = "text/json"
        response = []

        location = conn.execute("SELECT * FROM HTMLSettings WHERE idName=?", ("location",)).fetchone()[1]
        response.append({"id": "location", "type": "text", "content": location})

        locationDescription = conn.execute(
            "SELECT * FROM HTMLSettings WHERE idName=?", ("locationDescription",)
        ).fetchone()[1]
        response.append({"id": "location_description", "type": "text", "content": locationDescription})

        twitter_query = conn.execute("SELECT * FROM HTMLSettings WHERE idName=?", ("twitterQuery",)).fetchone()[1]
        response.append({"id": "twitter_query", "type": "text", "content": twitter_query})

        feed = conn.execute("SELECT * FROM HTMLSettings WHERE idName=?", ("feed",)).fetchone()[1]
        response.append({"id": "feed", "type": "text", "content": feed})

        socket_port = cherrypy.config.get("server.socket_port")

        addresses = "No IP address"
        ifaces = ["eth0", "wlan0"]
        for iface in ifaces:
            try:
                addresses = netifaces.ifaddresses(iface)[netifaces.AF_INET][0]["addr"] + ":" + str(socket_port)
            except (ValueError, KeyError):
                continue
            break
        response.append({"id": "ip", "type": "text", "content": addresses})
        return json.dumps(response)
Beispiel #2
0
    def dropbox(self, auth=0, pincode=None, note=None):
        date = datetime.datetime.now().strftime('%I:%M%p on %B %d, %Y')

        (app_key, app_secret) = conn.execute('SELECT AppKey, AppSecret FROM Dropbox').fetchone()

        auth_flow = DropboxOAuth2FlowNoRedirect(app_key, app_secret)

        if not auth:
            return auth_flow.start()

        if pincode:
            try:
                access_token, user_id = auth_flow.finish(pincode)
            except ErrorResponse, e:
                print('Error: %s' % (e,))
                return 'Unsuccessful.'

            print access_token
            if conn.execute('SELECT COUNT(*) FROM Dropbox WHERE AuthToken=?', (access_token,)).fetchone()[0]:
                rtn = 'Unsuccessful. Account already exists.'
            else:
                conn.execute('UPDATE Dropbox SET AuthToken=?, Note=?, DateAdded=? WHERE AppKey=?',
                             (access_token, note, date, app_key))
                conn.commit()
                rtn = 'Successful.'
            return rtn
Beispiel #3
0
    def dropbox(self, auth=0, pincode=None, note=None):
        date = datetime.datetime.now().strftime('%I:%M%p on %B %d, %Y')

        (app_key, app_secret
         ) = conn.execute('SELECT AppKey, AppSecret FROM Dropbox').fetchone()

        auth_flow = DropboxOAuth2FlowNoRedirect(app_key, app_secret)

        if not auth:
            return auth_flow.start()

        if pincode:
            try:
                access_token, user_id = auth_flow.finish(pincode)
            except ErrorResponse, e:
                print('Error: %s' % (e, ))
                return 'Unsuccessful.'

            print access_token
            if conn.execute('SELECT COUNT(*) FROM Dropbox WHERE AuthToken=?',
                            (access_token, )).fetchone()[0]:
                rtn = 'Unsuccessful. Account already exists.'
            else:
                conn.execute(
                    'UPDATE Dropbox SET AuthToken=?, Note=?, DateAdded=? WHERE AppKey=?',
                    (access_token, note, date, app_key))
                conn.commit()
                rtn = 'Successful.'
            return rtn
Beispiel #4
0
    def delete_link(self, link):
        find_id = conn.execute('SELECT * FROM YouTube WHERE VideoId = (?);', (link,)).fetchone()
        find_name = conn.execute('SELECT VideoName FROM YouTube WHERE VideoId = (?);', (link,)).fetchone()

        delete_video(find_name[0])

        conn.execute('DELETE FROM YouTube WHERE VideoId = (?);', (find_id[0],))
        conn.commit()
Beispiel #5
0
def save_file(path, f, file_type, message):
    out = open(os.path.join(ROOT_DIR, 'static/public/data/dropbox_files', path[1:]), 'w')
    out.write(f.read())
    out.close()
    conn.execute('INSERT OR IGNORE INTO Files(FilePath, ToDisplay, FileOrder, Type) VALUES (?, ?, ?, ?)',
                 (os.path.join(ROOT_DIR, 'static/public/data/dropbox_files', path), 1, -1, file_type,))
    conn.commit()
    updated_files.append(path)
    print 'SUCCESS: ' + path + ' was ' + message + '.'
Beispiel #6
0
 def services(self, servicelist):
     try:
         for service in json.loads(servicelist):
             conn.execute('UPDATE FrontEndOrder SET ToDisplay=?, ServicesOrder=? WHERE Service=?',
                          (service['todisplay'], service['order'], service['name'],))
         conn.commit()
         return 'Successful.'
     except sql.Error:
         return 'Unsuccessful.'
Beispiel #7
0
def copy_dropbox_folder():
    if client:
        copy_folder('/')
        for f in conn.execute('SELECT * FROM Files').fetchall():
            if f[0] not in updated_files:
                conn.execute('DELETE FROM Files WHERE FilePath=?', (f[0],))
                conn.commit()
                os.remove(os.path.join(ROOT_DIR, 'static/public/data/dropbox_files', f[0][1:]))
                print 'WARNING: The file with the path: ' + f[0] + ' was removed.'
Beispiel #8
0
 def tweets(self, tweetlist):
     try:
         for tweet in json.loads(tweetlist):
             conn.execute('UPDATE Tweets SET ToDisplay=?, TweetOrder=? WHERE TweetId=?',
                          (tweet['todisplay'], tweet['order'], tweet['tweetid'],))
         conn.commit()
         return 'Successful.'
     except sql.Error:
         return 'Unsuccessful.'
Beispiel #9
0
 def dropbox_db(files):
     try:
         for f in json.loads(files):
             conn.execute('UPDATE Files SET ToDisplay=?, FileOrder=? WHERE FilePath=?',
                          (f['todisplay'], f['order'], f['filepath'],))
         conn.commit()
         return 'Successful.'
     except sql.Error:
             return 'Unsuccessful.'
Beispiel #10
0
    def delete_link(self, link):
        find_id = conn.execute('SELECT * FROM YouTube WHERE VideoId = (?);',
                               (link, )).fetchone()
        find_name = conn.execute(
            'SELECT VideoName FROM YouTube WHERE VideoId = (?);',
            (link, )).fetchone()

        delete_video(find_name[0])

        conn.execute('DELETE FROM YouTube WHERE VideoId = (?);',
                     (find_id[0], ))
        conn.commit()
Beispiel #11
0
def copy_dropbox_folder():
    if client:
        copy_folder('/')
        for f in conn.execute('SELECT * FROM Files').fetchall():
            if f[0] not in updated_files:
                conn.execute('DELETE FROM Files WHERE FilePath=?', (f[0], ))
                conn.commit()
                os.remove(
                    os.path.join(ROOT_DIR, 'static/public/data/dropbox_files',
                                 f[0][1:]))
                print 'WARNING: The file with the path: ' + f[
                    0] + ' was removed.'
Beispiel #12
0
def populate_db(count=100):
    query = conn.execute('SELECT Content FROM HTMLSettings WHERE idName=?', ('twitterQuery',)).fetchone()[0]
    try:
        tweets = api.GetSearch(term=query, count=count)
        conn.execute('DELETE FROM Tweets WHERE TweetOrder > (SELECT TweetOrder FROM '
                     '(SELECT TweetOrder FROM Tweets ORDER BY TweetOrder ASC LIMIT 1 OFFSET 127))')
        for tweet in tweets:
            conn.execute('INSERT OR REPLACE INTO Tweets (TweetId, Author, Tweet, ToDisplay) VALUES '
                         '(?, ?, ?, COALESCE((SELECT ToDisplay FROM Tweets WHERE TweetId=?), 1))',
                         (tweet.id, tweet.user.name, tweet.text, tweet.id))
        conn.commit()
    except twitter.TwitterError, e:
        print e
Beispiel #13
0
 def dropbox_db(files):
     try:
         for f in json.loads(files):
             conn.execute(
                 'UPDATE Files SET ToDisplay=?, FileOrder=? WHERE FilePath=?',
                 (
                     f['todisplay'],
                     f['order'],
                     f['filepath'],
                 ))
         conn.commit()
         return 'Successful.'
     except sql.Error:
         return 'Unsuccessful.'
Beispiel #14
0
 def updateDB(self,
              location=None,
              locationDescription=None,
              background=None,
              twitterQuery=None,
              feed=None):
     if location:
         conn.execute('UPDATE HTMLSettings SET content=? WHERE idName=? ', (
             location,
             'location',
         ))
     if locationDescription:
         conn.execute('UPDATE HTMLSettings SET content=? WHERE idName=? ', (
             locationDescription,
             'locationDescription',
         ))
     if twitterQuery:
         conn.execute('UPDATE HTMLSettings SET content=? WHERE idName=? ',
                      (twitterQuery, 'twitterQuery'))
     if feed:
         conn.execute('UPDATE HTMLSettings SET content=? WHERE idName=? ', (
             feed,
             'feed',
         ))
     conn.commit()
Beispiel #15
0
 def tweets(self, tweetlist):
     try:
         for tweet in json.loads(tweetlist):
             conn.execute(
                 'UPDATE Tweets SET ToDisplay=?, TweetOrder=? WHERE TweetId=?',
                 (
                     tweet['todisplay'],
                     tweet['order'],
                     tweet['tweetid'],
                 ))
         conn.commit()
         return 'Successful.'
     except sql.Error:
         return 'Unsuccessful.'
Beispiel #16
0
 def services(self, servicelist):
     try:
         for service in json.loads(servicelist):
             conn.execute(
                 'UPDATE FrontEndOrder SET ToDisplay=?, ServicesOrder=? WHERE Service=?',
                 (
                     service['todisplay'],
                     service['order'],
                     service['name'],
                 ))
         conn.commit()
         return 'Successful.'
     except sql.Error:
         return 'Unsuccessful.'
Beispiel #17
0
    def tweets(self):
        all_tweets = []

        for tweet in conn.execute("SELECT * FROM Tweets WHERE ToDisplay=? ORDER BY TweetOrder ASC", ("1",)):
            all_tweets.append({"tweetid": str(tweet[0]), "author": tweet[1], "tweet": tweet[2], "order": tweet[4]})

        return json.dumps(all_tweets, separators=(",", ":"))
Beispiel #18
0
    def dropbox_files(self, file_type):
        cherrypy.response.headers['Content-Type'] = "application/json"
        all_files = []
        for f in conn.execute('SELECT * FROM Files WHERE Type=? ORDER BY FileOrder ASC', (file_type,)).fetchall():
            all_files.append({'filepath': f[0], 'todisplay': f[1], 'order': f[2], 'type': f[3]})

        return json.dumps(all_files, separators=(',', ':'))
Beispiel #19
0
    def services(self):
        cherrypy.response.headers['Content-Type'] = "application/json"
        all_services = []
        for service in conn.execute('SELECT * FROM FrontEndOrder ORDER BY ServicesOrder ASC').fetchall():
            all_services.append({'name': service[0], 'todisplay': service[1], 'order': service[2]})

        return json.dumps(all_services, separators=(',', ':'))
Beispiel #20
0
 def list_of_links(self):
     ids = conn.execute("SELECT * FROM YouTube;")
     ids = ids.fetchall()
     list_to_return = []
     for i in ids:
         list_to_return.append(i[0])
     return json.dumps({"status": 200, "content": list_to_return})
Beispiel #21
0
 def list_of_links(self):
     ids = conn.execute('SELECT * FROM YouTube;')
     ids = ids.fetchall()
     list_to_return = []
     for i in ids:
         list_to_return.append(i[0])
     return json.dumps({'status': 200, 'content': list_to_return})
Beispiel #22
0
    def HTMLChanges(self):
        cherrypy.response.headers['Content-Type'] = 'text/json'
        response = []

        location = conn.execute('SELECT * FROM HTMLSettings WHERE idName=?',
                                ('location', )).fetchone()[1]
        response.append({
            'id': 'location',
            'type': 'text',
            'content': location
        })

        locationDescription = conn.execute(
            'SELECT * FROM HTMLSettings WHERE idName=?',
            ('locationDescription', )).fetchone()[1]
        response.append({
            'id': 'location_description',
            'type': 'text',
            'content': locationDescription
        })

        twitter_query = conn.execute(
            'SELECT * FROM HTMLSettings WHERE idName=?',
            ('twitterQuery', )).fetchone()[1]
        response.append({
            'id': 'twitter_query',
            'type': 'text',
            'content': twitter_query
        })

        feed = conn.execute('SELECT * FROM HTMLSettings WHERE idName=?',
                            ('feed', )).fetchone()[1]
        response.append({'id': 'feed', 'type': 'text', 'content': feed})

        socket_port = cherrypy.config.get('server.socket_port')

        addresses = 'No IP address'
        ifaces = ['eth0', 'wlan0']
        for iface in ifaces:
            try:
                addresses = netifaces.ifaddresses(iface)[
                    netifaces.AF_INET][0]['addr'] + ':' + str(socket_port)
            except (ValueError, KeyError):
                continue
            break
        response.append({'id': 'ip', 'type': 'text', 'content': addresses})
        return json.dumps(response)
Beispiel #23
0
 def dropbox(self):
     cherrypy.response.headers['Content-Type'] = "application/json"
     dropbox = conn.execute('SELECT AuthToken, Note, DateAdded FROM Dropbox').fetchone()
     try:
         return json.dumps({'AuthToken': 'X' * len(dropbox[0][:-4]) + dropbox[0][-4:], 'Note': dropbox[1],
                            'DateAdded': dropbox[2]}, separators=(',', ':'))
     except TypeError:
         return 'No account added.'
Beispiel #24
0
    def tweets(self):
        cherrypy.response.headers['Content-Type'] = "application/json"
        all_tweets = []
        for tweet in conn.execute('SELECT * FROM Tweets ORDER BY TweetOrder ASC'):
            all_tweets.append({'tweetid': str(tweet[0]), 'author': tweet[1], 'tweet': tweet[2], 'todisplay': tweet[3],
                               'order': tweet[4]})

        return json.dumps(all_tweets, separators=(',', ':'))
Beispiel #25
0
def save_file(path, f, file_type, message):
    out = open(
        os.path.join(ROOT_DIR, 'static/public/data/dropbox_files', path[1:]),
        'w')
    out.write(f.read())
    out.close()
    conn.execute(
        'INSERT OR IGNORE INTO Files(FilePath, ToDisplay, FileOrder, Type) VALUES (?, ?, ?, ?)',
        (
            os.path.join(ROOT_DIR, 'static/public/data/dropbox_files', path),
            1,
            -1,
            file_type,
        ))
    conn.commit()
    updated_files.append(path)
    print 'SUCCESS: ' + path + ' was ' + message + '.'
Beispiel #26
0
    def front_order():
        all_services = []
        for service in conn.execute(
                'SELECT * FROM FrontEndOrder WHERE ToDisplay=? ORDER BY ServicesOrder ASC',
            ('1', )).fetchall():
            all_services.append({'name': service[0], 'order': service[2]})

        return all_services
Beispiel #27
0
    def dropbox_files(file_type):
        all_files = []
        for f in conn.execute(
            "SELECT * FROM Files WHERE Type=? AND ToDisplay=? ORDER BY FileOrder ASC", (file_type, "1")
        ).fetchall():
            all_files.append({"filepath": f[0], "todisplay": f[1], "order": f[2], "type": f[3]})

        return all_files
Beispiel #28
0
    def front_order():
        all_services = []
        for service in conn.execute(
            "SELECT * FROM FrontEndOrder WHERE ToDisplay=? ORDER BY ServicesOrder ASC", ("1",)
        ).fetchall():
            all_services.append({"name": service[0], "order": service[2]})

        return all_services
Beispiel #29
0
 def twitter(self):
     cherrypy.response.headers['Content-Type'] = "application/json"
     twitter = conn.execute('SELECT AccessKey, AccessSecret, Note, DateAdded FROM Twitter').fetchone()
     try:
         return json.dumps({'AccessKey': 'X' * len(twitter[0][:-4]) + twitter[0][-4:],
                            'AccessSecret': 'X' * len(twitter[1][:-4]) + twitter[1][-4:], 'Note': twitter[2],
                            'DateAdded': twitter[3]}, separators=(',', ':'))
     except TypeError:
         return 'No account added.'
Beispiel #30
0
 def updateDB(self, location=None, locationDescription=None, background=None, twitterQuery=None, feed=None):
     if location:
         conn.execute('UPDATE HTMLSettings SET content=? WHERE idName=? ', (location, 'location',))
     if locationDescription:
         conn.execute('UPDATE HTMLSettings SET content=? WHERE idName=? ',
                      (locationDescription, 'locationDescription',))
     if twitterQuery:
         conn.execute('UPDATE HTMLSettings SET content=? WHERE idName=? ', (twitterQuery, 'twitterQuery'))
     if feed:
         conn.execute('UPDATE HTMLSettings SET content=? WHERE idName=? ', (feed, 'feed',))
     conn.commit()
Beispiel #31
0
    def youtube():
        all_videos = []
        for video in conn.execute('SELECT * FROM YouTube').fetchall():
            all_videos.append({
                'link': video[0],
                'filepath': video[1].split("/static")[1],
                'name': video[2]
            })

        return all_videos
Beispiel #32
0
    def services(self):
        cherrypy.response.headers['Content-Type'] = "application/json"
        all_services = []
        for service in conn.execute(
                'SELECT * FROM FrontEndOrder ORDER BY ServicesOrder ASC'
        ).fetchall():
            all_services.append({
                'name': service[0],
                'todisplay': service[1],
                'order': service[2]
            })

        return json.dumps(all_services, separators=(',', ':'))
Beispiel #33
0
def deti_news():
    try:
        feed_source = conn.execute('SELECT * FROM HTMLSettings WHERE IdName=?', ('feed',)).fetchone()[1]
        feed_content = feedparser.parse(feed_source)

        news = {"title": feed_content.feed.title, "news": []}

        # delete all the images

        files = glob.glob(os.path.join(ROOT_DIR, 'static/public/data/feed_imgs/') + '*')
        for f in files:
            os.remove(f)

        conn.execute("DELETE FROM News;")

        for entry in feed_content.entries:
            news['news'] += [{'author': parse_author(entry.author) if hasattr(entry, 'author') else '',
                              'summary': entry.summary if hasattr(entry, 'summary') else '',
                              'title': entry.title if hasattr(entry, 'title') else '',
                              'date': parse_date(str(entry.updated)) if hasattr(entry, 'entry.updated') else ''}]

        for i in range(len(news['news'])):
            tmp = news["news"][i]['summary']
            new_tmp = download_photo(tmp)

            # try to clean...
            new_tmp = new_tmp.replace('<p class="MsoNormal"></p>', '')
            new_tmp = new_tmp.replace('<p></p>', '')
            new_tmp = new_tmp.replace('<br>', '')
            new_tmp = new_tmp.replace('<br />', '')
            new_tmp = new_tmp.replace('<p>&nbsp;</p>', '')

            # news without images
            tmp = tmp.replace('<p class="MsoNormal"></p>', '')
            tmp = tmp.replace('<p></p>', '')
            tmp = tmp.replace('<br>', '')
            tmp = tmp.replace('<br />', '')
            tmp = tmp.replace('<p>&nbsp;</p>', '')

            spaces = re.findall('(<p[^>]*><p[^>]*>.</p></p>&#13;)', new_tmp)
            for space in spaces:
                new_tmp = new_tmp.replace(space, "")
                tmp = tmp.replace(space, "")

            if new_tmp:
                conn.execute('INSERT INTO News (Title, Date_Updated, Author, Content) VALUES (?,?,?,?);',
                             (news['news'][i]['title'], news['news'][i]['date'], news['news'][i]['author'], new_tmp))
                conn.commit()
            else:
                conn.execute('INSERT INTO News (Title, Date_Updated, Author, Content) VALUES (?,?,?,?);',
                             (news['news'][i]['title'], news['news'][i]['date'], news['news'][i]['author'], tmp))
                conn.commit()
    except Exception, e:
        print e.message
Beispiel #34
0
    def tweets(self):
        all_tweets = []

        for tweet in conn.execute(
                'SELECT * FROM Tweets WHERE ToDisplay=? ORDER BY TweetOrder ASC',
            ('1', )):
            all_tweets.append({
                'tweetid': str(tweet[0]),
                'author': tweet[1],
                'tweet': tweet[2],
                'order': tweet[4]
            })

        return json.dumps(all_tweets, separators=(',', ':'))
Beispiel #35
0
 def dropbox(self):
     cherrypy.response.headers['Content-Type'] = "application/json"
     dropbox = conn.execute(
         'SELECT AuthToken, Note, DateAdded FROM Dropbox').fetchone()
     try:
         return json.dumps(
             {
                 'AuthToken': 'X' * len(dropbox[0][:-4]) + dropbox[0][-4:],
                 'Note': dropbox[1],
                 'DateAdded': dropbox[2]
             },
             separators=(',', ':'))
     except TypeError:
         return 'No account added.'
Beispiel #36
0
    def dropbox_files(self, file_type):
        cherrypy.response.headers['Content-Type'] = "application/json"
        all_files = []
        for f in conn.execute(
                'SELECT * FROM Files WHERE Type=? ORDER BY FileOrder ASC',
            (file_type, )).fetchall():
            all_files.append({
                'filepath': f[0],
                'todisplay': f[1],
                'order': f[2],
                'type': f[3]
            })

        return json.dumps(all_files, separators=(',', ':'))
Beispiel #37
0
    def tweets(self):
        cherrypy.response.headers['Content-Type'] = "application/json"
        all_tweets = []
        for tweet in conn.execute(
                'SELECT * FROM Tweets ORDER BY TweetOrder ASC'):
            all_tweets.append({
                'tweetid': str(tweet[0]),
                'author': tweet[1],
                'tweet': tweet[2],
                'todisplay': tweet[3],
                'order': tweet[4]
            })

        return json.dumps(all_tweets, separators=(',', ':'))
Beispiel #38
0
    def dropbox_files(file_type):
        all_files = []
        for f in conn.execute(
                'SELECT * FROM Files WHERE Type=? AND ToDisplay=? ORDER BY FileOrder ASC',
            (
                file_type,
                '1',
            )).fetchall():
            all_files.append({
                'filepath': f[0],
                'todisplay': f[1],
                'order': f[2],
                'type': f[3]
            })

        return all_files
Beispiel #39
0
 def user(self, current_password=None, new_password=None, first_name=None, last_name=None, email=None):
     if not ((current_password and new_password) or first_name or last_name or email):
         raise cherrypy.HTTPRedirect('/admin/pages/profile.html#error=No parameters received')
     username = cherrypy.session[SESSION_USER]['UserId']
     date = datetime.datetime.now().strftime('%B %d, %Y')
     if current_password and new_password:
         if current_password == conn.execute('SELECT Password FROM Users WHERE UserId=?', (username,)).fetchone()[0]:
             conn.execute('UPDATE Users SET Password=?, Date=? WHERE UserId=?',
                          (new_password, date, username))
         else:
             raise cherrypy.HTTPRedirect('/admin/pages/profile.html#error=Wrong password')
     if first_name:
         conn.execute('UPDATE Users SET FirstName=?, Date=? WHERE UserId=?', (first_name, date, username))
         cherrypy.session[SESSION_USER]['FirstName'] = first_name
     if last_name:
         conn.execute('UPDATE Users SET LastName=?, Date=? WHERE UserId=?', (last_name, date, username))
         cherrypy.session[SESSION_USER]['LastName'] = last_name
     if email:
         conn.execute('UPDATE Users SET Email=?, Date=? WHERE UserId=?', (email, date, username))
         cherrypy.session[SESSION_USER]['Email'] = email
     conn.commit()
     raise cherrypy.HTTPRedirect('/admin/pages/profile.html')
Beispiel #40
0
    def twitter(self, clear=0, pincode=None, note=None):
        date = datetime.datetime.now().strftime('%I:%M%p on %B %d, %Y')

        if clear:
            self.resp = None
            return 'Successful'

        (consumer_key, consumer_secret) = conn.execute('SELECT ConsumerKey, ConsumerSecret FROM Twitter').fetchone()
        oauth_client = OAuth1Session(consumer_key, client_secret=consumer_secret)

        if not self.resp:  # Else a temp token was already generated
            # Requesting a temp token from Twitter
            try:
                self.resp = oauth_client.fetch_request_token(self.REQUEST_TOKEN_URL)
            except ValueError, e:
                raise cherrypy.HTTPRedirect(
                        '/admin/pages/accounts.html#error=Invalid response from Twitter requesting temp token: %s' % e)
Beispiel #41
0
 def twitter(self):
     cherrypy.response.headers['Content-Type'] = "application/json"
     twitter = conn.execute(
         'SELECT AccessKey, AccessSecret, Note, DateAdded FROM Twitter'
     ).fetchone()
     try:
         return json.dumps(
             {
                 'AccessKey': 'X' * len(twitter[0][:-4]) + twitter[0][-4:],
                 'AccessSecret':
                 'X' * len(twitter[1][:-4]) + twitter[1][-4:],
                 'Note': twitter[2],
                 'DateAdded': twitter[3]
             },
             separators=(',', ':'))
     except TypeError:
         return 'No account added.'
Beispiel #42
0
 def user(self,
          current_password=None,
          new_password=None,
          first_name=None,
          last_name=None,
          email=None):
     if not ((current_password and new_password) or first_name or last_name
             or email):
         raise cherrypy.HTTPRedirect(
             '/admin/pages/profile.html#error=No parameters received')
     username = cherrypy.session[SESSION_USER]['UserId']
     date = datetime.datetime.now().strftime('%B %d, %Y')
     if current_password and new_password:
         if current_password == conn.execute(
                 'SELECT Password FROM Users WHERE UserId=?',
             (username, )).fetchone()[0]:
             conn.execute(
                 'UPDATE Users SET Password=?, Date=? WHERE UserId=?',
                 (new_password, date, username))
         else:
             raise cherrypy.HTTPRedirect(
                 '/admin/pages/profile.html#error=Wrong password')
     if first_name:
         conn.execute('UPDATE Users SET FirstName=?, Date=? WHERE UserId=?',
                      (first_name, date, username))
         cherrypy.session[SESSION_USER]['FirstName'] = first_name
     if last_name:
         conn.execute('UPDATE Users SET LastName=?, Date=? WHERE UserId=?',
                      (last_name, date, username))
         cherrypy.session[SESSION_USER]['LastName'] = last_name
     if email:
         conn.execute('UPDATE Users SET Email=?, Date=? WHERE UserId=?',
                      (email, date, username))
         cherrypy.session[SESSION_USER]['Email'] = email
     conn.commit()
     raise cherrypy.HTTPRedirect('/admin/pages/profile.html')
Beispiel #43
0
def checkpassword(realm, username, password):
    """
    Check if 'username' can be authenticated. Works as a login would
    """
    if SESSION_LOGIN in cherrypy.session and not cherrypy.session[SESSION_LOGIN]:
        cherrypy.session[SESSION_LOGIN] = True
        return False
    user = conn.execute('SELECT * FROM Users WHERE UserId=?', (username,)).fetchone()
    if user and user[1] == password:
        cherrypy.session[SESSION_USER] = {
            'UserId': user[0],
            'FirstName': user[2],
            'LastName': user[3],
            'Email': user[4],
            'Date': user[5]
        }
        cherrypy.session[SESSION_LOGIN] = True
        return True
    return False
Beispiel #44
0
def checkpassword(realm, username, password):
    """
    Check if 'username' can be authenticated. Works as a login would
    """
    if SESSION_LOGIN in cherrypy.session and not cherrypy.session[
            SESSION_LOGIN]:
        cherrypy.session[SESSION_LOGIN] = True
        return False
    user = conn.execute('SELECT * FROM Users WHERE UserId=?',
                        (username, )).fetchone()
    if user and user[1] == password:
        cherrypy.session[SESSION_USER] = {
            'UserId': user[0],
            'FirstName': user[2],
            'LastName': user[3],
            'Email': user[4],
            'Date': user[5]
        }
        cherrypy.session[SESSION_LOGIN] = True
        return True
    return False
Beispiel #45
0
    def save_link(self, link):

        videoUrl = link
        videoJson = 'http://www.youtube.com/oembed?url=' + videoUrl + '&format=json'

        response = requests.get(videoJson)
        if response.status_code == 404:
            return json.dumps({'status': 404})

        find_id = conn.execute('SELECT * FROM YouTube WHERE VideoId = (?);', (link,)).fetchall()

        # check if the URL wasn't added
        if len(find_id):
            return json.dumps({'status': 500})

        try:
            subprocess.Popen(['python', os.path.join(ROOT_DIR, __file__), link])
        except cherrypy.TimeoutError:
            pass

        return json.dumps({'status': 200})
Beispiel #46
0
    def twitter(self, clear=0, pincode=None, note=None):
        date = datetime.datetime.now().strftime('%I:%M%p on %B %d, %Y')

        if clear:
            self.resp = None
            return 'Successful'

        (consumer_key, consumer_secret) = conn.execute(
            'SELECT ConsumerKey, ConsumerSecret FROM Twitter').fetchone()
        oauth_client = OAuth1Session(consumer_key,
                                     client_secret=consumer_secret)

        if not self.resp:  # Else a temp token was already generated
            # Requesting a temp token from Twitter
            try:
                self.resp = oauth_client.fetch_request_token(
                    self.REQUEST_TOKEN_URL)
            except ValueError, e:
                raise cherrypy.HTTPRedirect(
                    '/admin/pages/accounts.html#error=Invalid response from Twitter requesting temp token: %s'
                    % e)
Beispiel #47
0
    def save_link(self, link):

        videoUrl = link
        videoJson = 'http://www.youtube.com/oembed?url=' + videoUrl + '&format=json'

        response = requests.get(videoJson)
        if response.status_code == 404:
            return json.dumps({'status': 404})

        find_id = conn.execute('SELECT * FROM YouTube WHERE VideoId = (?);',
                               (link, )).fetchall()

        # check if the URL wasn't added
        if len(find_id):
            return json.dumps({'status': 500})

        try:
            subprocess.Popen(
                ['python', os.path.join(ROOT_DIR, __file__), link])
        except cherrypy.TimeoutError:
            pass

        return json.dumps({'status': 200})
Beispiel #48
0
            except ValueError, e:
                raise cherrypy.HTTPRedirect(
                        '/admin/pages/accounts.html#error=Invalid response from Twitter requesting temp token: %s' % e)

        if not pincode:  # Else pin code is already known
            # URL to the pin code page (used to obtain an Authentication Token)
            return oauth_client.authorization_url(self.AUTHORIZATION_URL)

        # Generating and signing request for an access token
        oauth_client = OAuth1Session(consumer_key, client_secret=consumer_secret,
                                     resource_owner_key=self.resp.get('oauth_token'),
                                     resource_owner_secret=self.resp.get('oauth_token_secret'),
                                     verifier=pincode)
        try:
            resp = oauth_client.fetch_access_token(self.ACCESS_TOKEN_URL)
            conn.execute('UPDATE Twitter SET AccessKey=?, AccessSecret=?, Note=?, DateAdded=? WHERE ConsumerKey=?',
                         (resp.get('oauth_token'), resp.get('oauth_token_secret'), note, date, consumer_key))
            conn.commit()
        except ValueError, e:
            raise cherrypy.HTTPRedirect(
                    '/admin/pages/accounts.html#error=Invalid respond from Twitter requesting access token: %s' % e)

        return 'Successful'


class Get:
    def __init__(self):
        pass

    @cherrypy.expose
    def dropbox(self):
        cherrypy.response.headers['Content-Type'] = "application/json"
Beispiel #49
0
def download(link):
    yt = pytube.YouTube()

    # Set the video URL.
    yt.from_url(link)

    # Once set, you can see all the codec and quality options YouTube has made
    # available for the particular video by printing videos.

    # pprint(yt.get_videos())

    # [<Video: MPEG-4 Visual (.3gp) - 144p>,
    # <Video: MPEG-4 Visual (.3gp) - 240p>,
    # <Video: Sorenson H.263 (.flv) - 240p>,
    # <Video: H.264 (.flv) - 360p>,
    # <Video: H.264 (.flv) - 480p>,
    # <Video: H.264 (.mp4) - 360p>,
    # <Video: H.264 (.mp4) - 720p>,
    # <Video: VP8 (.webm) - 360p>,
    # <Video: VP8 (.webm) - 480p>]

    # The filename is automatically generated based on the video title.
    # You can override this by manually setting the filename.

    # view the auto generated filename:
    # print(yt.filename)

    # Pulp Fiction - Dancing Scene [HD]

    # set the filename:
    # yt.set_filename('example')

    # You can also filter the criteria by filetype.

    # pprint(yt.filter('flv'))

    # [<Video: Sorenson H.263 (.flv) - 240p>,
    # <Video: H.264 (.flv) - 360p>,
    # <Video: H.264 (.flv) - 480p>]

    # notice that the list is ordered by lowest resolution to highest. If you
    # wanted the highest resolution available for a specific file type, you
    # can simply do:
    # print(yt.filter('mp4')[-1])
    # <Video: H.264 (.mp4) - 720p>

    # you can also get all videos for a given resolution
    videos = yt.filter(extension='mp4') or yt.filter(extension='webm')

    if not len(videos):
        return json.dumps({'status': 400})

    video = None
    for v in videos:
        if v.resolution >= '360p':
            video = v
            break

    if video is None:
        video = videos[-1]

    # [<Video: H.264 (.flv) - 480p>,
    # <Video: VP8 (.webm) - 480p>]

    # to select a video by a specific resolution and filetype you can use the get
    # method.

    # NOTE: get() can only be used if and only if one object matches your criteria.
    # for example:

    # pprint(yt.videos)

    # [<Video: MPEG-4 Visual (.3gp) - 144p>,
    # <Video: MPEG-4 Visual (.3gp) - 240p>,
    # <Video: Sorenson H.263 (.flv) - 240p>,
    # <Video: H.264 (.flv) - 360p>,
    # <Video: H.264 (.flv) - 480p>,
    # <Video: H.264 (.mp4) - 360p>,
    # <Video: H.264 (.mp4) - 720p>,
    # <Video: VP8 (.webm) - 360p>,
    # <Video: VP8 (.webm) - 480p>]

    # Notice we have two H.264 (.mp4) available to us.. now if we try to call get()
    # on mp4..

    # video = yt.get('mp4')
    # MultipleObjectsReturned: get() returned more than one object -- it returned 2!

    # In this case, we'll need to specify both the codec (mp4) and resolution
    # (either 360p or 720p).

    # Okay, let's download it!
    # try:
    video.download(os.path.join(ROOT_DIR, 'static/public/data/videos/'))
    # except Exception:
    #    return json.dumps({'status': 400})
    # Downloading: Pulp Fiction - Dancing Scene.mp4 Bytes: 37561829
    # 37561829  [100.00%]

    # Note: If you wanted to choose the output directory, simply pass it as an
    # argument to the download method.
    # video.download('/tmp/')

    conn.execute('INSERT INTO YouTube VALUES (?,?,?);',
                 (link, os.path.join(ROOT_DIR, 'static/public/data/videos/' + yt.filename + '.mp4'), yt.filename))
    conn.commit()
Beispiel #50
0
    def youtube():
        all_videos = []
        for video in conn.execute("SELECT * FROM YouTube").fetchall():
            all_videos.append({"link": video[0], "filepath": video[1].split("/static")[1], "name": video[2]})

        return all_videos
Beispiel #51
0
        if not pincode:  # Else pin code is already known
            # URL to the pin code page (used to obtain an Authentication Token)
            return oauth_client.authorization_url(self.AUTHORIZATION_URL)

        # Generating and signing request for an access token
        oauth_client = OAuth1Session(
            consumer_key,
            client_secret=consumer_secret,
            resource_owner_key=self.resp.get('oauth_token'),
            resource_owner_secret=self.resp.get('oauth_token_secret'),
            verifier=pincode)
        try:
            resp = oauth_client.fetch_access_token(self.ACCESS_TOKEN_URL)
            conn.execute(
                'UPDATE Twitter SET AccessKey=?, AccessSecret=?, Note=?, DateAdded=? WHERE ConsumerKey=?',
                (resp.get('oauth_token'), resp.get('oauth_token_secret'), note,
                 date, consumer_key))
            conn.commit()
        except ValueError, e:
            raise cherrypy.HTTPRedirect(
                '/admin/pages/accounts.html#error=Invalid respond from Twitter requesting access token: %s'
                % e)

        return 'Successful'


class Get:
    def __init__(self):
        pass

    @cherrypy.expose
Beispiel #52
0
                    'INSERT INTO News (Title, Date_Updated, Author, Content) VALUES (?,?,?,?);',
                    (news['news'][i]['title'], news['news'][i]['date'],
                     news['news'][i]['author'], new_tmp))
                conn.commit()
            else:
                conn.execute(
                    'INSERT INTO News (Title, Date_Updated, Author, Content) VALUES (?,?,?,?);',
                    (news['news'][i]['title'], news['news'][i]['date'],
                     news['news'][i]['author'], tmp))
                conn.commit()
    except Exception, e:
        print e.message

    news_db = []

    for i in conn.execute('SELECT * FROM News;').fetchall():
        news_db.append({
            'author': i[3],
            'summary': i[4],
            'title': i[1],
            'date': i[2]
        })

    return news_db


def parse_author(author):
    if '=?iso-8859-1?Q?' in author:
        slices = urllib.unquote(author.replace('=', '%').replace(
            '"', '')).replace('?%', '').split("%?iso-8859-1?Q?")
        author = ""
Beispiel #53
0
def deti_news():
    try:
        feed_source = conn.execute('SELECT * FROM HTMLSettings WHERE IdName=?',
                                   ('feed', )).fetchone()[1]
        feed_content = feedparser.parse(feed_source)

        news = {"title": feed_content.feed.title, "news": []}

        # delete all the images

        files = glob.glob(
            os.path.join(ROOT_DIR, 'static/public/data/feed_imgs/') + '*')
        for f in files:
            os.remove(f)

        conn.execute("DELETE FROM News;")

        for entry in feed_content.entries:
            news['news'] += [{
                'author':
                parse_author(entry.author) if hasattr(entry, 'author') else '',
                'summary':
                entry.summary if hasattr(entry, 'summary') else '',
                'title':
                entry.title if hasattr(entry, 'title') else '',
                'date':
                parse_date(str(entry.updated)) if hasattr(
                    entry, 'entry.updated') else ''
            }]

        for i in range(len(news['news'])):
            tmp = news["news"][i]['summary']
            new_tmp = download_photo(tmp)

            # try to clean...
            new_tmp = new_tmp.replace('<p class="MsoNormal"></p>', '')
            new_tmp = new_tmp.replace('<p></p>', '')
            new_tmp = new_tmp.replace('<br>', '')
            new_tmp = new_tmp.replace('<br />', '')
            new_tmp = new_tmp.replace('<p>&nbsp;</p>', '')

            # news without images
            tmp = tmp.replace('<p class="MsoNormal"></p>', '')
            tmp = tmp.replace('<p></p>', '')
            tmp = tmp.replace('<br>', '')
            tmp = tmp.replace('<br />', '')
            tmp = tmp.replace('<p>&nbsp;</p>', '')

            spaces = re.findall('(<p[^>]*><p[^>]*>.</p></p>&#13;)', new_tmp)
            for space in spaces:
                new_tmp = new_tmp.replace(space, "")
                tmp = tmp.replace(space, "")

            if new_tmp:
                conn.execute(
                    'INSERT INTO News (Title, Date_Updated, Author, Content) VALUES (?,?,?,?);',
                    (news['news'][i]['title'], news['news'][i]['date'],
                     news['news'][i]['author'], new_tmp))
                conn.commit()
            else:
                conn.execute(
                    'INSERT INTO News (Title, Date_Updated, Author, Content) VALUES (?,?,?,?);',
                    (news['news'][i]['title'], news['news'][i]['date'],
                     news['news'][i]['author'], tmp))
                conn.commit()
    except Exception, e:
        print e.message
Beispiel #54
0
import twitter
from constants import conn

(consumer_key, consumer_secret, access_token_key, access_token_secret) = conn.execute(
        'SELECT ConsumerKey, ConsumerSecret, AccessKey, AccessSecret FROM Twitter').fetchone()

api = twitter.Api(consumer_key=consumer_key,
                  consumer_secret=consumer_secret,
                  access_token_key=access_token_key,
                  access_token_secret=access_token_secret)


def populate_db(count=100):
    query = conn.execute('SELECT Content FROM HTMLSettings WHERE idName=?', ('twitterQuery',)).fetchone()[0]
    try:
        tweets = api.GetSearch(term=query, count=count)
        conn.execute('DELETE FROM Tweets WHERE TweetOrder > (SELECT TweetOrder FROM '
                     '(SELECT TweetOrder FROM Tweets ORDER BY TweetOrder ASC LIMIT 1 OFFSET 127))')
        for tweet in tweets:
            conn.execute('INSERT OR REPLACE INTO Tweets (TweetId, Author, Tweet, ToDisplay) VALUES '
                         '(?, ?, ?, COALESCE((SELECT ToDisplay FROM Tweets WHERE TweetId=?), 1))',
                         (tweet.id, tweet.user.name, tweet.text, tweet.id))
        conn.commit()
    except twitter.TwitterError, e:
        print e
Beispiel #55
0
def download(link):
    yt = pytube.YouTube()

    # Set the video URL.
    yt.from_url(link)

    # Once set, you can see all the codec and quality options YouTube has made
    # available for the particular video by printing videos.

    # pprint(yt.get_videos())

    # [<Video: MPEG-4 Visual (.3gp) - 144p>,
    # <Video: MPEG-4 Visual (.3gp) - 240p>,
    # <Video: Sorenson H.263 (.flv) - 240p>,
    # <Video: H.264 (.flv) - 360p>,
    # <Video: H.264 (.flv) - 480p>,
    # <Video: H.264 (.mp4) - 360p>,
    # <Video: H.264 (.mp4) - 720p>,
    # <Video: VP8 (.webm) - 360p>,
    # <Video: VP8 (.webm) - 480p>]

    # The filename is automatically generated based on the video title.
    # You can override this by manually setting the filename.

    # view the auto generated filename:
    # print(yt.filename)

    # Pulp Fiction - Dancing Scene [HD]

    # set the filename:
    # yt.set_filename('example')

    # You can also filter the criteria by filetype.

    # pprint(yt.filter('flv'))

    # [<Video: Sorenson H.263 (.flv) - 240p>,
    # <Video: H.264 (.flv) - 360p>,
    # <Video: H.264 (.flv) - 480p>]

    # notice that the list is ordered by lowest resolution to highest. If you
    # wanted the highest resolution available for a specific file type, you
    # can simply do:
    # print(yt.filter('mp4')[-1])
    # <Video: H.264 (.mp4) - 720p>

    # you can also get all videos for a given resolution
    videos = yt.filter(extension='mp4') or yt.filter(extension='webm')

    if not len(videos):
        return json.dumps({'status': 400})

    video = None
    for v in videos:
        if v.resolution >= '360p':
            video = v
            break

    if video is None:
        video = videos[-1]

    # [<Video: H.264 (.flv) - 480p>,
    # <Video: VP8 (.webm) - 480p>]

    # to select a video by a specific resolution and filetype you can use the get
    # method.

    # NOTE: get() can only be used if and only if one object matches your criteria.
    # for example:

    # pprint(yt.videos)

    # [<Video: MPEG-4 Visual (.3gp) - 144p>,
    # <Video: MPEG-4 Visual (.3gp) - 240p>,
    # <Video: Sorenson H.263 (.flv) - 240p>,
    # <Video: H.264 (.flv) - 360p>,
    # <Video: H.264 (.flv) - 480p>,
    # <Video: H.264 (.mp4) - 360p>,
    # <Video: H.264 (.mp4) - 720p>,
    # <Video: VP8 (.webm) - 360p>,
    # <Video: VP8 (.webm) - 480p>]

    # Notice we have two H.264 (.mp4) available to us.. now if we try to call get()
    # on mp4..

    # video = yt.get('mp4')
    # MultipleObjectsReturned: get() returned more than one object -- it returned 2!

    # In this case, we'll need to specify both the codec (mp4) and resolution
    # (either 360p or 720p).

    # Okay, let's download it!
    # try:
    video.download(os.path.join(ROOT_DIR, 'static/public/data/videos/'))
    # except Exception:
    #    return json.dumps({'status': 400})
    # Downloading: Pulp Fiction - Dancing Scene.mp4 Bytes: 37561829
    # 37561829  [100.00%]

    # Note: If you wanted to choose the output directory, simply pass it as an
    # argument to the download method.
    # video.download('/tmp/')

    conn.execute(
        'INSERT INTO YouTube VALUES (?,?,?);',
        (link,
         os.path.join(ROOT_DIR, 'static/public/data/videos/' + yt.filename +
                      '.mp4'), yt.filename))
    conn.commit()
Beispiel #56
0
import time

import dropbox
import os
from constants import ROOT_DIR, conn

try:
    access_token = conn.execute('SELECT AuthToken FROM Dropbox').fetchone()[0]
    client = dropbox.client.DropboxClient(access_token)
except ValueError:
    print('Dropbox account not added.')
    client = None

updated_files = []


def copy_dropbox_folder():
    if client:
        copy_folder('/')
        for f in conn.execute('SELECT * FROM Files').fetchall():
            if f[0] not in updated_files:
                conn.execute('DELETE FROM Files WHERE FilePath=?', (f[0],))
                conn.commit()
                os.remove(os.path.join(ROOT_DIR, 'static/public/data/dropbox_files', f[0][1:]))
                print 'WARNING: The file with the path: ' + f[0] + ' was removed.'


def copy_folder(path):
    for f in list_files(path):
        if f['is_dir']:
            download_folder(f['path'])
Beispiel #57
0
                tmp = tmp.replace(space, "")

            if new_tmp:
                conn.execute('INSERT INTO News (Title, Date_Updated, Author, Content) VALUES (?,?,?,?);',
                             (news['news'][i]['title'], news['news'][i]['date'], news['news'][i]['author'], new_tmp))
                conn.commit()
            else:
                conn.execute('INSERT INTO News (Title, Date_Updated, Author, Content) VALUES (?,?,?,?);',
                             (news['news'][i]['title'], news['news'][i]['date'], news['news'][i]['author'], tmp))
                conn.commit()
    except Exception, e:
        print e.message

    news_db = []

    for i in conn.execute('SELECT * FROM News;').fetchall():
        news_db.append({'author': i[3], 'summary': i[4], 'title': i[1], 'date': i[2]})

    return news_db


def parse_author(author):
    if '=?iso-8859-1?Q?' in author:
        slices = urllib.unquote(author.replace('=', '%').replace('"', '')).replace('?%', '').split("%?iso-8859-1?Q?")
        author = ""
        for slice in slices:
            author += slice.strip().replace("_", " ")
    return author


def parse_date(date):
Beispiel #58
0
import time

import dropbox
import os
from constants import ROOT_DIR, conn

try:
    access_token = conn.execute('SELECT AuthToken FROM Dropbox').fetchone()[0]
    client = dropbox.client.DropboxClient(access_token)
except ValueError:
    print('Dropbox account not added.')
    client = None

updated_files = []


def copy_dropbox_folder():
    if client:
        copy_folder('/')
        for f in conn.execute('SELECT * FROM Files').fetchall():
            if f[0] not in updated_files:
                conn.execute('DELETE FROM Files WHERE FilePath=?', (f[0], ))
                conn.commit()
                os.remove(
                    os.path.join(ROOT_DIR, 'static/public/data/dropbox_files',
                                 f[0][1:]))
                print 'WARNING: The file with the path: ' + f[
                    0] + ' was removed.'


def copy_folder(path):