Skip to content

Instantly share code, notes, and snippets.

@FodT
Last active May 3, 2017 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FodT/cd218824dfad1fbb8513 to your computer and use it in GitHub Desktop.
Save FodT/cd218824dfad1fbb8513 to your computer and use it in GitHub Desktop.
quick hello world demo of campaign/strategy/concept/creative creation and assignment.
# runs in python 3.4
from terminalone import T1
from terminalone.utils import credentials
from terminalone import models
from datetime import datetime, timedelta
ADVERTISER_ID = YOUR_ADVERTISER_ID
t1 = T1(auth_method='cookie', **credentials())
c = t1.new(models.Campaign)
c.name = 'test campaign'
c.advertiser_id = ADVERTISER_ID
c.ad_server_id = 6
c.goal_value = 1
c.status = True
c.start_date = datetime.now() + timedelta(1)
c.end_date = datetime.now() + timedelta(10)
c.service_type = 'SELF'
c.goal_type = 'spend'
c.total_budget = 1
c.save()
print('created campaign id {}'.format(c.id))
CAMPAIGN_ID = c.id
s = t1.new(models.Strategy)
s.campaign_id = CAMPAIGN_ID
s.name = 'test strategy'
s.budget = 1
s.status = False # true to enable spend
s.pacing_amount = 1
s.goal_type = 'spend'
s.type = 'REM'
s.use_campaign_start = True
s.use_campaign_end = True
s.save()
print('created strategy id {}'.format(s.id))
STRATEGY_ID = s.id
concept = t1.new(models.Concept)
concept.name = 'test concept'
concept.advertiser_id = ADVERTISER_ID
concept.save()
print('created concept id {}'.format(concept.id))
CONCEPT_ID = concept.id
creative = t1.new(models.AtomicCreative)
creative.name = 'test creative'
creative.advertiser_id = ADVERTISER_ID
creative.external_identifier = 'extid12345'
creative.width = 1000
creative.height = 400
creative.tpas_ad_tag_name = 'image-tag'
creative.tag = 'https://google.co.uk'
creative.tag_type = 'IMG'
creative.concept_id = CONCEPT_ID # here's how you assign a creative to a concept after pulling/creating it
creative.save()
print('created creative id {}'.format(creative.id))
CREATIVE_ID = creative.id
# assign the concept to the strategy
sc = t1.new(models.StrategyConcept)
sc.strategy_id = STRATEGY_ID
sc.concept_id = CONCEPT_ID
sc.save()
print('created strategy concept id {}'.format(sc.id))
# get the concept[s] assigned to your strategy
c1 = t1.get('strategies', STRATEGY_ID, child='concepts')
# this could potentially return a generator, but there's only one here right now.
print('got concept: {}'.format(c1.id))
# get the strategy concept pair[s] on your strategy
# this is a generator
sc2 = t1.get('strategy_concepts', limit={'strategy': STRATEGY_ID}, full=True)
sc = next(sc2)
print('deleting strategyconcept id {} for strategy id {} and concept id {}'.format(sc.id, sc.strategy_id, sc.concept_id))
sc.remove()
@FodT
Copy link
Author

FodT commented Apr 7, 2016

This script makes the assumption that your T1_API_KEY, T1_API_PASSWORD and T1_API_USERNAME environment variables are defined and readable by the python process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment