NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import SocketServer
from cgi import parse_header, parse_multipart
from urlparse import parse_qs
import sqlite3
from datetime import datetime, timedelta
import time


import requests
import json

def get_page_data(token , postvars):
print 'Fetching updated page token'
url = 'https://graph.facebook.com/v2.9/me/accounts?access_token=' + token
resp = requests.get(url)

data = json.loads(resp.text)['data']
result_pages = []
for p in postvars['pages[]']:
for d in data:
if p == d['id']:
result_pages.append(d)

return result_pages

def schedule_url(postvars):
short_token = postvars['access_token'][0]

print 'Fetching long token...'
url = 'https://graph.facebook.com/v2.9/oauth/access_token?grant_type=fb_exchange_token&client_id=' +
'430639957295822&client_secret=535e308cfa2f1d62e1b5f3088783e496&fb_exchange_token=' + short_token

resp = requests.get(url)
long_token = json.loads(resp.text)['access_token']

result_pages = get_page_data(long_token , postvars)

print result_pages

name = postvars['name'][0]

result = {}
result['time'] = postvars['time'][0]
result['pages'] = result_pages


print json.dumps(result)

print 'Storing all details in db'
conn = sqlite3.connect('test.db')
c = conn.cursor()

c1 = c.execute('DELETE FROM token WHERE name=?', (name, ))
c2 = c.execute('DELETE FROM schedule_time') ;

sql_insert = (name , json.dumps(result) )

c3 = c.execute('INSERT INTO token VALUES (? , ?)', sql_insert)

c4 = c.execute('INSERT INTO schedule_time VALUES (?)', (postvars['time'][0],) )


conn.commit()
conn.close()
return True


def get_links(url):
result = []
loop = True
while loop:
resp = requests.get(url)
resp_obj = json.loads(resp.text)
print resp_obj

if 'data' in resp_obj:
for obj in resp_obj['data']:
if obj['type'] == 'link':
result.append(obj)

if 'paging' in resp_obj and resp_obj['paging'] and 'next' in resp_obj['paging']:
url = resp_obj['paging']['next']
loop = True
else:
loop = False

return result



def delete_post(postvars):
short_token = postvars['access_token'][0]
result_pages = get_page_data(short_token , postvars)
print result_pages
ext = postvars['delete_extensions'][0]
extensions = ext.split(',')

extensions = [x.strip(' ') for x in extensions]
print extensions
start_date = datetime.now()
day_minus_3 = start_date- timedelta(hours=52)
day_minus_15 = start_date- timedelta(days=15)

start_epoch = str(int(time.mktime(day_minus_15.timetuple())))
end_epoch = str(int(time.mktime(day_minus_3.timetuple())))


delete_count = 0
for page in result_pages:
print "Fetching Posts for " + page['name']

url_str = page['id'] + "/posts?include_hidden=true&fields=created_time,id,message,link,type&limit=100&since=" + start_epoch + "&until=" + end_epoch + '&access_token=' + page['access_token'];

print url_str
url = 'https://graph.facebook.com/v2.9/' + url_str

links = get_links(url)

if links and len(links) > 0:
for obj in links:
if obj['type'] == 'link':
from urlparse import urlparse
o = urlparse(obj['link'])
bool_delete = False
for e in extensions:
if o.netloc.endswith(e):
bool_delete = True
break
if bool_delete:
hide_url = 'https://graph.facebook.com/v2.9/' + obj['id'] + '?access_token=' + page['access_token']
print "Deleting " + obj['id']
resp = requests.delete(hide_url)
print resp.text
delete_count +=1
else:
print "Nothing to hide"

return 'Deleted ' + str(delete_count) + ' posts'


class S(BaseHTTPRequestHandler):
def _set_headers(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()

def do_GET(self):
self._set_headers()
with open("hide_me.html") as fh:
self.wfile.write(fh.read())

def do_HEAD(self):
self._set_headers()

def do_POST(self):
# Doesn't do anything with posted data
ctype, pdict = parse_header(self.headers['content-type'])
if ctype == 'multipart/form-data':
postvars = parse_multipart(self.rfile, pdict)
elif ctype == 'application/x-www-form-urlencoded':
length = int(self.headers['content-length'])
postvars = parse_qs(
self.rfile.read(length),
keep_blank_values=1)
else:
postvars = {}

result = ''
if(self.path == '/'):
schedule_url(postvars)
result ="Schedule Updated"
elif(self.path == '/delete'):
result = delete_post(postvars)


content = result
self.send_response(200)
self.send_header("Content-type","text/json")
self.send_header("Content-Length", len(content))
self.end_headers()
self.wfile.write(content)

def run(server_class=HTTPServer, handler_class=S, port=8880):
server_address = ('', port)
httpd = server_class(server_address, handler_class)
print 'Starting httpd...'
httpd.serve_forever()

if __name__ == "__main__":
from sys import argv

if len(argv) == 2:
run(port=int(argv[1]))
else:
run()
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.