Esempio n. 1
0
def new_ad():
    if request.method == 'GET':
        return render_template('new_ad.html', ads=Ad.all())
    elif request.method == 'POST':
        ad = Ad.find(request.form['ad_id'])
        values = (None, request.form['title'], request.form['description'],
                  request.form['price'], request.form['date'],
                  request.form['is_active'], request.form['buyer'], ad)
        Ad(*values).create()

        return redirect('/')
Esempio n. 2
0
 def get_ads(self):
     results = self.content('.container-results').find('.search-item')
     ads = []
     for result in results:
         preview = pq(result)
         ads.append(Ad(preview))
     return ads
Esempio n. 3
0
def read_near_ads(latitude, longitude, distance):
	'''
	This function reads, serializes and returns all tupples in Ad table that
	their geographical location is nearer than distance (Killometer) in order.
	Instead of using GIS database extensions, SqlAlchemy Hybrid method and Great Circle
	formula are used here to query the database for calculating the distances.
	'''
	try:
		ads = db.session.query(
			Ad,
			Ad.distance(latitude, longitude).label('distance'),
			Ad.agency_id,
			Ad.name,
			Ad.latitude,
			Ad.longitude
		).having(db.column('distance') <= distance).order_by('distance').all()
		ads_json = [{
		'agency_id' : ad.agency_id,
		'name': ad.name,
    	'latitude': float(ad.latitude),
    	'longitude': float(ad.longitude),
    	'distance': ad.distance
    	} for ad in ads]
		return ads_json
	except Exception as e:
		print('error while reading near ads: ' + str(e))
		return None
Esempio n. 4
0
 def write_csv(self, ad: Ad):
     metro = ad.get_closest_station()
     self.writer.writerow({
         'id': ad.get_id(),
         'url': ad.get_url(),
         'has_washer': 'yes' if ad.is_washer_mentioned() else 'no',
         'metro station': metro[0],
         'metro distance': metro[1],
         'title': ad.get_title_components()[0],
         'score': ad.get_score(),
         'price': ad.get_price(),
         'date': ad.get_posted_date()
     })
Esempio n. 5
0
 def setUp(self):
     self.kyokuto_anime_snippet_ad = Ad({
         'title':
         'a',
         'snippet':
         '極東アニメーションで素敵な作品を描こう',
         'link':
         'http://www.pref.nara.jp/item/83513.htm'
     })
     self.chuni_snippet_ad = Ad({
         'title':
         'a',
         'snippet':
         '夢ならたくさん見た',
         'link':
         'http://www.pref.nara.jp/item/83513.htm'
     })
     self.health_title_ad = Ad({
         'title':
         '健康を気にするなら',
         'snippet':
         's',
         'link':
         'http://www.pref.nara.jp/item/83513.htm'
     })
     self.trigger_snippet_ad = Ad({
         'title':
         'TRIGGERのキルラキルでアニメの新世界を見よう。あの今石洋之なら世界を変えられる!',
         'snippet':
         'TRIGGERのキルラキルでアニメの新世界を見よう。あの今石洋之なら世界を変えられる!',
         'link':
         'http://www.pref.nara.jp/item/83513.htm'
     })
     self.sakuga_snippet_ad = Ad({
         'title':
         't',
         'snippet':
         'あのグレートウルトラアニメなら銀河特急新幹線を超えられる',
         'link':
         'http://www.pref.nara.jp/item/83513.htm'
     })
Esempio n. 6
0
 def set_ads_with_html_body(self):
     listWrap = pq(self.html_body).find('.listWrap')
     lis = listWrap.children().children()
     ads = []
     for li in lis:
         pq_li = pq(li)
         title = pq_li.find('a').text()
         link = pq_li.find('a').attr('href')
         snippet = pq_li.find('.smr').text()
         ad = Ad(title=title, snippet=snippet, link=link)
         ads.append(ad)
     self.ads = ads
Esempio n. 7
0
    def fetch_ads(self, context):
        print('fetch query')
        print('query: ', self.query.url)
        html_doc = get(self.query.url).text
        soup = BeautifulSoup(html_doc, 'html.parser')
        ads = soup.find_all('a', {'class': 'post-card-link'})
        ad_links = [ad['href'] for ad in ads]
        new_ads = set(ad_links) - self.history
        print('len ads:', len(new_ads))

        if not self.history:
            self.history = new_ads
            return

        for ad_url in new_ads:
            url = urljoin(self.query.base_url, ad_url)
            ad = Ad(url=url)
            ad.fetch()
            self.send(ad)
            self.history.add(ad_url)

        return new_ads
Esempio n. 8
0
 def post(self):
     parser = reqparse.RequestParser()
     try:
         parser.add_argument('width', type=int)
         parser.add_argument('height', type=int)
         parser.add_argument('creative', type=str)
         args = parser.parse_args()
         adid = str(uuid.uuid4())
         newad = Ad(adid, args['width'], args['height'], args['creative'])
         store[adid] = newad
         return {"args": args, "status": "success"}
     except:
         return {"args": args, "status": "error"}
Esempio n. 9
0
 def fetch_ads(self):
     nlist = pq(self.html).find('.nlist')
     lis = nlist.children().children()
     ads = []
     for li in lis:
         pq_li = pq(li)
         title = pq_li.find('a').text()
         link = pq_li.find('a').attr('href')
         snippet = pq_li.find('.yschabstr').text()
         ad_info = {'title': title, 'snippet': snippet, 'link': link}
         ad = Ad(ad_info)
         ads.append(ad)
     return ads
Esempio n. 10
0
def create_ad(agency_id, name, latitude, longitude):
	'''
	This function creates a new tupple in Ad table.
	return 0 means everything accomplished successfully.
	return 1 means the operation was unsuccessfull.
	'''
	try:
		ad = Ad(agency_id, name, latitude, longitude)
		db.session.add(ad)
		db.session.commit()
		return 0
	except Exception as e:
		print('error while creating the ad: ' + str(e))
		return 1
Esempio n. 11
0
    def __init__(self,
                 id_raffle: str,
                 name: str,
                 ad: Ad,
                 duration: float = 60):
        self._id_raffle = id_raffle
        self._name_raffle = name
        self._ad = ad  # Ojeto anuncio Asociado
        self._id_ad = ad.show_properties()[0]
        self._started = 0
        self._finished = 0

        self._time_duration = duration  # Seconds of a day
        self._time_start = 0
        self._time_raffle = 0
        self._time_stop = 0

        self._prize_money = 0
        self._participants = list()
        self._id_participants = list()
        self._number_winners = 1
        self._id_winners = list()
        self._winners = list()
Esempio n. 12
0
 def attachAd(self, settings):
     ad = Ad(settings)
     self.ads.append(ad)
     return ad
Esempio n. 13
0
def get_categories():
    return render_template("categories.html", categories=Ad.all())
Esempio n. 14
0
def buy_ad(id):
    ad = Ad.find(id)
    ad.buy()

    return redirect('/')
Esempio n. 15
0
def delete_ad(id):
    ad = Ad.find(id)
    ad.delete()

    return redirect('/')
Esempio n. 16
0
def show_ad(id):
    ad = Ad.find(id)

    return render_template('ad.html', ad=ad)
Esempio n. 17
0
from base_model import BaseAdvertising
from ad import Ad
from advertiser import Advertiser

if __name__ == "__main__":
    baseAdvertising = BaseAdvertising()
    advertiser1 = Advertiser('name1')
    advertiser2 = Advertiser('name2')
    ad1 = Ad("title1", "img-url1", "link1", advertiser1)
    ad2 = Ad("title2", "img-url2", "link2", advertiser2)
    baseAdvertising.describeMe()
    ad2.describeMe()
    advertiser1.describeMe()
    ad1.incViews()
    ad1.incViews()
    ad1.incViews()
    ad1.incViews()
    ad2.incViews()
    ad1.incClicks()
    ad1.incClicks()
    ad2.incClicks()
    advertiser2.getName()
    advertiser2.setName("new name")
    advertiser2.getName()
    ad1.getClicks()
    advertiser2.getClicks()
    Advertiser.getTotalClicks()
    Advertiser.help()
Esempio n. 18
0
 def insert(self, ad: Ad):
     cursor = self.db.cursor()
     cursor.execute(
         '''REPLACE INTO ads(
         id,
         title,
         url,
         description,
         postedTime,
         price,
         rooms,
         isNothingIncluded,
         score,
         isLate,
         isBasement,
         isWasherMentioned,
         closestMetro,
         closestMetroDistance
         ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)''',
         (ad.get_id(), ad.get_title_components()[0], ad.get_url(),
          ad.get_description(),
          int(
              datetime.strptime(
                  ad.get_posted_date(),
                  '%Y-%m-%d %H:%M:%S').timestamp()), ad.get_price(),
          ad.get_size(), ad.is_nothing_included(), ad.get_score(),
          ad.is_too_late(), ad.is_basement(), ad.is_washer_mentioned(),
          ad.get_closest_station()[0], ad.get_closest_station()[1]))
     self.db.commit()
Esempio n. 19
0
from baseAdvertising import BaseAdvertising
from ad import Ad
from advertiser import Advertiser

baseAdvertising = BaseAdvertising()
advertiser1 = Advertiser(1, "name1")
advertiser2 = Advertiser(2, "name2")
ad1 = Ad(1, "title1", "img-url1", "link1", advertiser1)
ad2 = Ad(2, "title2", "img-url2", "link2", advertiser2)
print(baseAdvertising.describe_me())
print(ad2.describe_me())
print(advertiser1.describe_me())
ad1.inc_views()
ad1.inc_views()
ad1.inc_views()
ad1.inc_views()
ad2.inc_views()
ad1.inc_clicks()
ad1.inc_clicks()
ad2.inc_clicks()
print(advertiser2.name)
advertiser2.name = "new name"
print(advertiser2.name)
print(ad1.clicks)
print(advertiser2.clicks)
print(Advertiser.get_total_clicks())
print(Advertiser.help())
 def __init__(self):
     self._nome = 'Resultado'
     self._dados = []
     self.lista = []
     self.lista.append(Ad())
     self.lista.append(Result())
Esempio n. 21
0
def list_ads():
    return render_template('ads.html', ads=Ad.all())
Esempio n. 22
0
from base_model import BaseAdvertising
from ad import Ad
from advertiser import Advertiser

if __name__ == '__main__':
    baseAdvertising = BaseAdvertising
    advertiser1 = Advertiser(1, "name1")
    advertiser2 = Advertiser(2, "name2")
    ad1 = Ad(1, "title1", "img-url1", "link1", advertiser1)
    ad2 = Ad(2, "title2", "img-url2", "link2", advertiser2)
    ad1.incViews()
    ad1.incViews()
    ad1.incViews()
    ad1.incViews()
    ad2.incViews()
    ad1.incClicks()
    ad1.incClicks()
    ad2.incClicks()
    print(advertiser2.getName())
    advertiser2.setName("new name")
    print(advertiser2.getName())
    print(ad1.getClicks())
    print(advertiser2.getClicks())
    print(Advertiser.getTotalClicks())