Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,26 @@ facebot is divided by two components. the masterbot.py script is the one that de

## how to use this tool:

Open `conf/info.conf` and fill in your info; you can change `fbotDB`.

Before you install req*, do

```
sudo apt-get install build-essential python-dev libmysqlclient-dev
```
The latter will is needed by MySQL-Python,
The latter is needed by MySQL-Python,

```
pip install -r requirements.txt
```


---


'Warning: before executing masterbot you need to create the DB in order to store all the loot. the database squema in jpg form is shown on the repo'.
~~'Warning: before executing masterbot you need to create the DB in order to store all the loot. the database squema in jpg form is shown on the repo'.~~

`masterbot.py` will create the db for you, given `conf/info.conf` is correct.

'warning: in order to leverage "target_mode" a fake facebook app needs to be created and an access token be created.' these steps were done manually due to lack of dev time but thats on the works...

Expand Down Expand Up @@ -86,5 +91,16 @@ current_city:
hometown:

"facebook id of the city as per facebook"



#Instructions for getting target_mode to work

Until the process is automated, please use the following:

1. Login to https://developers.facebook.com/ and create an app
2. Go to or `GET` https://graph.facebook.com/oauth/access_token?client_id=YOUR APP ID&client_secret=YOUR APP SECRET&grant_type=client_credentials
3. Got to https://developers.facebook.com/tools/explorer and place the `access_token` from the latter request to where it says `Access Token`. Click on `Get Access Token`
4. Copy the `Access Token` and paste it in your config file; `api_key:`


any questions or suggestions on how to improve this tool i can be contacted at luiguibiker@gmail.com please use the subject [facebot] so i can better track the email.
5 changes: 5 additions & 0 deletions conf/info.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[SYS]
host=
user=
pass=
db=fbotDB
107 changes: 107 additions & 0 deletions db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''
Copyright (c) 2014 mad_dev, mad_dev@linuxmail.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'''

import MySQLdb
import ConfigParser



class sql:

def __init__(self, host, user, pwd, dbname):
self.host = host
self.user = user
self.pwd = pwd
self.dbname = dbname

def create_database(self):
db = MySQLdb.connect(host=self.host, user=self.user, passwd=self.pwd)
cur = db.cursor()
sql_create = 'CREATE DATABASE %s' %self.dbname
sql_use = 'USE %s' %self.dbname
cur.execute(sql_create)
cur.execute(sql_use)
cur.execute('''CREATE TABLE fbids (
fbid BIGINT(20),
sent TEXT,
crawled VARCHAR(20)
)'''
)

cur.execute('''CREATE TABLE checkins (
checkin_id CHAR(32),
fbid BIGINT(20),
message TEXT,
coords TEXT,
timestamp TIMESTAMP
)'''
)

cur.execute('''CREATE TABLE users (
fbid BIGINT(20),
profile_url TEXT,
name TEXT,
contact_email TEXT,
interests TEXT,
birthday VARCHAR(20),
hometown_location TEXT,
relationship_status TEXT,
significant_other_id TEXT,
education TEXT,
work VARCHAR(100),
sex TEXT,
devices VARCHAR(100)
)'''

)

cur.execute('''CREATE TABLE family (
fbid BIGINT(20),
relative_id CHAR(32),
name VARCHAR(80),
relationship VARCHAR(100)
)'''
)

db.commit()
cur.close()
db.close()


class Conf:

def __init__(self):
pass

def getConf(self):
configData = {}
config = ConfigParser.ConfigParser()
config.read('conf/info.conf')
options = config.options('SYS')
for i in options:
configData[i] = config.get('SYS', i)

return configData

61 changes: 55 additions & 6 deletions masterBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import time
import hashlib
import datetime
import sys
import db


categories = ["Autos","Music","Travel","Animals","Sports","Comedy","People","Entertainment","News","Howto","Education","Tech","Nonprofit","Movies"]
Expand All @@ -50,12 +52,38 @@
vLink = vLink.replace("&feature=youtube_gdata_player","")
yt_videos.append(vLink)

config_file = db.Conf()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should have its own function

param = config_file.getConf()
host = param['host']
user = param['user']
password = param['pass']
dbname = param['db']

try:
dbconn = MySQLdb.connect("127.0.0.1","user","pass","DBname" )
dbconn = MySQLdb.connect(host, user, password, dbname )
cursor = dbconn.cursor()

except Exception as ex:
print ex

print 'Could not connect to db: %s' %dbname
db_create = db.sql(host, user, password, dbname)

try:
print 'Creating database'
db_create.create_database()
print 'Created %s' %dbname
dbconn = MySQLdb.connect(host, user, password, dbname )
cursor = dbconn.cursor()

'''^ Needed for first time launch'''

except Exception as e:
'''Should add proper error handling as to pinpoint the exception'''
code = re.findall(r'\d+', str(e))
if '1007' in code:
print 'Database already exists'
else:
print "Please check your credentials"

def addFbids(fbids):
print "processing received fbid's....."
Expand Down Expand Up @@ -132,6 +160,7 @@ def execute_sql(sql):
except Exception as ex:
print ex


def process_loot(cargo):

fbid = ''
Expand All @@ -142,15 +171,35 @@ def process_loot(cargo):
if k1 == 'about_me':
print "saving about me section on database... "
work=interests = hometown_location = relationship_status= name=devices=sex=significant_other_id= birthday = contact_email=education=profile_url =''

columns = ','.join(v1[0].keys())
interests = v1[0]['interests']
hometown_location = v1[0]['hometown_location']['name']
#hometown_location = v1[0]['hometown_location']['name']
'''
hometown_location fails 'NoneType' object has no attribute '__getitem__' if "hometown_location": null. rm ['name'] fixes it.
Confirmation needed
'''
try:
hometown_location = v1[0]['hometown_location']['name']
#print hometown_location
except:
#print 'Hometown not found'
pass

relationship_status = v1[0]['relationship_status']
name = v1[0]['name']
#devices = v1[0]['devices'][0]
devices = v1[0]['devices'][0]['os']

print devices
#devices = v1[0]['devices'][0]['os']
'''
devices fails 'NoneType' object has no attribute '__getitem__' if "devices": null.
'''
try:
devices = v1[0]['devices'][0]['os']
#print devices
except:
#print 'No devices found'
pass

sex = v1[0]['sex']
significant_other_id = v1[0]['significant_other_id']
if v1[0]['work']:
Expand Down