Skip to content
This repository was archived by the owner on Jul 29, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
d2d8870
fix reqs
Oct 21, 2021
441cfd6
delete FB users from custom audience
Oct 21, 2021
22b17dc
urllib & selenium package update
Jan 21, 2022
b69ab84
Merge pull request #1 from bxjw/fbRemoveUsers
bxjw Jan 21, 2022
0fdb473
requests upgrade
Jan 21, 2022
be9d9ed
Merge branch 'master' of https://github.com/bxjw/parsons
Jan 21, 2022
8e50087
Update requirements.txt
bxjw Jan 24, 2022
8bd6d7c
Merge branch 'master' of https://github.com/move-coop/parsons
Mar 1, 2022
54c0555
Merge branch 'master' of https://github.com/bxjw/parsons
Mar 1, 2022
9efc2ae
would you believe me if I said this was v12 LAST WEEK
Mar 7, 2022
6f93f02
fewer reqs
Mar 9, 2022
4e7d838
try this?
Mar 9, 2022
a53fb54
Merge branch 'move-coop:master' into noDeps
bxjw Mar 9, 2022
e363d08
don't get the aws session token
Mar 9, 2022
5465a3e
testing a thing
Mar 9, 2022
324b7db
more testing
Mar 9, 2022
4138184
asldfjk
Mar 9, 2022
2de375f
explicit no session token
Mar 9, 2022
9176c70
empty string env
Mar 9, 2022
95a5d70
Add sandbox instructions (#626)
shaunagm Mar 3, 2022
4107f98
Remove unused file (#627)
cmc333333 Mar 3, 2022
2f61a36
Update reference to license (#628)
shaunagm Mar 3, 2022
9a7e934
Update Parsons version number for 0.18.1 release (#629)
SorenSpicknall Mar 3, 2022
cd5caaa
don't get the aws session token
Mar 9, 2022
eb4060e
testing a thing
Mar 9, 2022
a8cca00
more testing
Mar 9, 2022
20a9c8f
asldfjk
Mar 9, 2022
d2d6c23
explicit no session token
Mar 9, 2022
d7e8778
empty string env
Mar 9, 2022
194f8b9
Merge branch 'move-coop:master' into master
bxjw Mar 9, 2022
bd33d22
facebook temporary v13
Mar 17, 2022
7a168be
Merge branch 'noDeps' of https://github.com/bxjw/parsons into noDeps
Mar 17, 2022
7790112
https instead of git
Mar 17, 2022
a5fd078
specify egg?
Mar 17, 2022
7965057
maybe this format?
Mar 17, 2022
ca3e4d9
facebook v13 finally exists
bxjw Apr 6, 2022
b3f0abd
Merge branch 'main' of https://github.com/move-coop/parsons
Apr 26, 2022
8545e83
Merge branch 'master' into noDeps
Apr 26, 2022
2590bf4
Update requirements.txt
bxjw May 2, 2022
f90b075
Update requirements.txt
bxjw May 30, 2022
55d0a5e
Update requirements.txt
bxjw May 30, 2022
5870c45
revert
bxjw May 31, 2022
c46baf6
Update requirements.txt
bxjw Aug 27, 2022
89f9648
Merge remote-tracking branch 'upstream/main' into noDeps
Aug 27, 2022
d7349a0
Merge branch 'noDeps' of https://github.com/bxjw/parsons into noDeps
Aug 27, 2022
a3760ec
Update requirements.txt
bxjw Aug 27, 2022
2636a8f
Update requirements.txt
bxjw Aug 27, 2022
bee59e0
Update requirements.txt
bxjw Sep 22, 2022
42ebc12
Update requirements.txt
bxjw Oct 27, 2022
645bf6f
Merge branch 'main' of https://github.com/move-coop/parsons into noDeps
Dec 13, 2022
341f6a5
fb 16
bxjw Feb 22, 2023
1346347
fb 17
bxjw Feb 8, 2024
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
2 changes: 1 addition & 1 deletion parsons/aws/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, aws_access_key_id=None, aws_secret_access_key=None, aws_sessi

self.session = boto3.Session(aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
aws_session_token=aws_session_token)
aws_session_token='')

else:
self.session = boto3.Session()
Expand Down
73 changes: 49 additions & 24 deletions parsons/facebook_ads/facebook_ads.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,50 @@ def _add_batch_to_custom_audience(app_id, app_secret, access_token, audience_id,
CustomAudience(audience_id).add_users(schema, batch, is_raw=True)
logger.info(f"Added {added_so_far+len(batch)}/{total_rows} users to custom audience...")

def _remove_batch_from_custom_audience(app_id, app_secret, access_token, audience_id, schema,
batch, added_so_far, total_rows):
FacebookAdsApi.init(app_id, app_secret, access_token)

CustomAudience(audience_id).remove_users(schema, batch, is_raw=True)
logger.info(f"Removed {added_so_far+len(batch)}/{total_rows} users from custom audience...")

def _change_users_in_custom_audience(self, audience_id, users_table, adding=True):
match_table = FacebookAds.get_match_table_for_users_table(users_table)
if not match_table.columns:
raise KeyError("No valid columns found for audience matching. "
"See FacebookAds.KeyMatchMap for supported columns")

num_rows = match_table.num_rows
logger.info(f"Found {num_rows} rows with valid FB matching keys")
logger.info(f"Using FB matching keys: {match_table.columns}")

(schema, data) = FacebookAds._get_match_schema_and_data(match_table)

# Use the FB API to add users, respecting the limit per API call.
# Process and upload batches in parallel, to improve performance.

batch_size = MAX_FB_AUDIENCE_API_USERS

if adding:
parallel_jobs = (
delayed(FacebookAds._add_batch_to_custom_audience)(
self.app_id, self.app_secret, self.access_token, audience_id, schema,
data[i:i+batch_size], i, num_rows
)
for i in range(0, len(data), batch_size)
)
else:
parallel_jobs = (
delayed(FacebookAds._remove_batch_from_custom_audience)(
self.app_id, self.app_secret, self.access_token, audience_id, schema,
data[i:i+batch_size], i, num_rows
)
for i in range(0, len(data), batch_size)
)

n_jobs = os.environ.get('PARSONS_NUM_PARALLEL_JOBS', 4)
Parallel(n_jobs=n_jobs)(parallel_jobs)

def add_users_to_custom_audience(self, audience_id, users_table):
"""
Adds user data to a custom audience.
Expand Down Expand Up @@ -352,29 +396,10 @@ def add_users_to_custom_audience(self, audience_id, users_table):
logger.info(f"Adding custom audience users from provided table with "
f"{users_table.num_rows} rows")

match_table = FacebookAds.get_match_table_for_users_table(users_table)
if not match_table.columns:
raise KeyError("No valid columns found for audience matching. "
"See FacebookAds.KeyMatchMap for supported columns")

num_rows = match_table.num_rows
logger.info(f"Found {num_rows} rows with valid FB matching keys")
logger.info(f"Using FB matching keys: {match_table.columns}")
FacebookAds._change_users_in_custom_audience(self, audience_id, users_table)

(schema, data) = FacebookAds._get_match_schema_and_data(match_table)

# Use the FB API to add users, respecting the limit per API call.
# Process and upload batches in parallel, to improve performance.

batch_size = MAX_FB_AUDIENCE_API_USERS

parallel_jobs = (
delayed(FacebookAds._add_batch_to_custom_audience)(
self.app_id, self.app_secret, self.access_token, audience_id, schema,
data[i:i+batch_size], i, num_rows
)
for i in range(0, len(data), batch_size)
)
def remove_users_from_custom_audience(self, audience_id, users_table):
logger.info(f"Removing custom audience users from provided table with "
f"{users_table.num_rows} rows")

n_jobs = os.environ.get('PARSONS_NUM_PARALLEL_JOBS', 4)
Parallel(n_jobs=n_jobs)(parallel_jobs)
FacebookAds._change_users_in_custom_audience(self, audience_id, users_table, adding=False)
63 changes: 32 additions & 31 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
requests==2.25.1
petl==1.6.8
requests==2.27.1
petl==1.7.11
boto3==1.17.98
boxsdk==2.10.0
civis==1.16.0
slackclient==1.3.0
psycopg2-binary==2.9.3
#boxsdk==2.10.0
#civis==1.16.0
#slackclient==1.3.0
#psycopg2-binary==2.9.3
xmltodict==0.11.0
gspread==3.7.0
oauth2client==4.1.3
google-auth==2.6.2
facebook-business==13.0.0
facebook-business==17.0.0
# facebook_business @ git+https://github.com/stac-labs/facebook-python-business-sdk.git@main
google-api-python-client==1.7.7
google-resumable-media==2.3.2
grpcio==1.45.0
#google-resumable-media==2.3.2
grpcio==1.48.0
httplib2==0.19.0
validate-email==1.3
paramiko==2.11.0
xmltodict==0.11.0
joblib==1.2.0
censusgeocode==0.4.3.post1
airtable-python-wrapper==0.13.0
google-cloud-storage==2.2.0
google-cloud-bigquery==3.0.1
#censusgeocode==0.4.3.post1
#airtable-python-wrapper==0.13.0
google-cloud-storage>=2.2.0
google-cloud-bigquery>=2.24.1
docutils<0.18,>=0.14
urllib3==1.26.5
urllib3==1.26.8
simplejson==3.16.0
twilio==6.30.0
simple-salesforce==1.11.6
# twilio==6.30.0
# simple-salesforce==0.74.3
suds-py3==1.3.4.0
newmode==0.1.6
mysql-connector-python==8.0.18
braintree==4.0.0
# newmode==0.1.6
# mysql-connector-python==8.0.18
# braintree==4.0.0
python-dateutil==2.8.1
azure-storage-blob==12.3.2
PyGitHub==1.51
surveygizmo==1.2.3
# azure-storage-blob==12.3.2
# PyGitHub==1.51
# surveygizmo==1.2.3
PyJWT==2.4.0 # Otherwise `import jwt` would refer to python-jwt package
SQLAlchemy==1.3.23
requests_oauthlib==1.3.0

# Testing Requirements
requests-mock==1.5.2
flake8==4.0.1
testfixtures==6.18.5
pytest==7.1.1
pytest-datadir==1.3.0
# requests-mock==1.5.2
# flake8==4.0.1
# testfixtures==6.18.5
# pytest==7.1.1
# pytest-datadir==1.3.0

# Stuff for TMC scripts
# TODO Remove when we have a TMC-specific Docker image
selenium==3.141.0
jinja2==3.0.2
# # Stuff for TMC scripts
# # TODO Remove when we have a TMC-specific Docker image
# selenium==4.1.0
# jinja2==3.0.2