本文整理汇总了Python中src.common.database.Database类的典型用法代码示例。如果您正苦于以下问题:Python Database类的具体用法?Python Database怎么用?Python Database使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Database类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_database
def update_database(genre):
show = Show(None, None, None, None, None)
page_no = 0
titles = show_title(genre, page_no)
print(titles)
ratings=find_ratings(titles)
#print(ratings)
trailers=find_trailer_link(titles)
#print(trailers)
release_dates=show_release_date(genre,page_no)
poster_link=show_poster_link(genre,page_no)
i=0
while i<30:
show._id=i+1
show.title=titles[i]
show.rating=ratings[i]
show.trailer=trailers[i]
show.release_date=release_dates[i]
show.poster=poster_link[i]
show.save_to_mongo(genre)
i=i+1
print("Database Updated")
Database.remove_all(genre+"_last_updated")
def json(): #can be removed, just done during testing something
d = str(datetime.date.today())
return {
"last_updated_date": d
}
Database.insert(genre+"_last_updated", json())
示例2: sync_to_db
def sync_to_db(self):
if self._synced is False:
Database.update(self.COLLECTION,
{'quiz_id': self._id, 'user_id': self._id},
{'passed': self._passed,
'try_number': self._try_number,
'last_try': self._last_try,})
示例3: test_one_shift_in_range_returns_none_for_other_days
def test_one_shift_in_range_returns_none_for_other_days(self):
user = User('[email protected]', 'u3', username='u3', _id='u3')
user.save_to_database()
# USER HAS SHIFT FOT ONLY MONDAY
start = beginning_of_week()
end = start + timedelta(seconds=1)
# create 1 second shift
shift = Shift(user._id, start, end)
shift.save_to_database()
schedule = Schedule(user._id)
# Monday is not None
self.assertEqual(type(schedule.shifts[0]), type(shift))
self.assertEqual(schedule.row[1], None)
self.assertEqual(schedule.row[2], None)
self.assertEqual(schedule.row[3], None)
self.assertEqual(schedule.row[4], None)
self.assertEqual(schedule.row[5], None)
self.assertEqual(schedule.row[6], None)
Database.remove('users', {'user_id': user._id})
Database.remove('shifts', {'user_id': user._id})
示例4: remove_from_db
def remove_from_db(self):
if self._feed:
news = [article for article in Database.find("articles", {"page_id" : uuid.UUID('{00000000-0000-0000-0000-000000000000}')})]
for article in news:
article = Article.get_by_id(article['_id'])
article.remove_from_db()
Database.remove(self.COLLECTION, {'_id': self._id})
示例5: tester_method
def tester_method():
email=request.form['email']
print(email)
user=User.get_by_email(email)
Database.update("users",{"email":email},{"printdata":"no"})
return "done"
示例6: calculate_portfolio
def calculate_portfolio(self, portfolio_id):
finance_data = Database.find_one('financedata', {"portfolio_id": self.portfolio_id})
if finance_data is not None:
Database.remove('financedata', {"portfolio_id": self.portfolio_id})
stock_data = Database.find('stockdata', {"portfolio_id": portfolio_id})
current_value_list = []
add_price_list = []
qty_list = []
for data in stock_data:
current_price = (data['current_price'])
add_price = (data['add_price'])
qty = (data['qty'])
current_value_list.append(current_price)
add_price_list.append(add_price)
qty_list.append(qty)
total_qty = sum(qty_list)
total_current_value = sum(current_value_list)
total_add_price = sum(add_price_list)
print(total_current_value)
try:
total_purchase_value = total_add_price * total_qty
total_current_value = total_current_value * total_qty
percent_change = (total_current_value - total_purchase_value) / total_current_value
finance = Finance(portfolio_id=portfolio_id, percent_change=percent_change,
total_purchase_value=total_purchase_value, total_current_value=total_current_value)
finance.save_to_database()
except ZeroDivisionError:
print("You need to add data first!")
示例7: set_user_attended
def set_user_attended(user, event):
if EventRegister.get_user_attended(user, event):
Database.update("registrations", {"user": user, "event": uuid.UUID(event)}, {"$set": {"attended": "No"}},
upsert=True)
else:
Database.update("registrations", {"user": user, "event": uuid.UUID(event)}, {"$set": {"attended": "Yes"}},
upsert=True)
示例8: remove_room
def remove_room(self):
_id = self._id
Database.remove('pointssetting', {'_id':_id})
Database.remove('players', {'room_id':_id})
Database.remove('matches', {'room_id': _id})
Database.remove('playersall', {'room_id': _id})
Database.remove(collection='rooms', data=self.json())
session['_id'] = None
示例9: get_registered_events
def get_registered_events(user):
events_registered_for = Database.find("registrations", {"user": user})
if events_registered_for is not None:
events = list()
for event in events_registered_for:
events.append(Database.find_one("events", {"_id": event["event"]}))
return events
return None
示例10: get_all_attended
def get_all_attended(user):
events_attended = Database.find("registrations", {"user": user, "attended": "Yes"})
if events_attended is not None:
events = list()
for event in events_attended:
events.append(Database.find_one("events", {"_id": event["event"]}))
return events
return None
示例11: home
def home(genre = 'comedy'):
#date=Database.find_coloumn(genre+'_last_updated','last_updated_date')
#if Database.count_all(genre+'_last_updated') > 0:
# if date[0]['last_updated_date']!=str(datetime.date.today()):
# update_database(genre)
#else:
# update_database(genre)
#update_database(genre)
print("Site Visited")
t=Database.find_coloumn(genre,"title")
new_title=[None]*30
new_trailer = [None] * 30
new_dates=[None]*30
new_ratings=[None]*30
new_poster_links=[None]*30
i=0
for title in t:
new_title[i]=title['title']
i=i+1
i=0
trailers = Database.find_coloumn(genre,"trailer")
for trailer in trailers:
new_trailer[i]=trailer['trailer']
i=i+1
i=0
release_dates = Database.find_coloumn(genre, "release_date")
for date in release_dates:
new_dates[i] = date['release_date']
i = i + 1
i = 0
ratings = Database.find_coloumn(genre, "rating")
for rating in ratings:
new_ratings[i] = rating['rating']
i = i + 1
i=0
poster_links = Database.find_coloumn(genre, "poster")
for poster_link in poster_links:
new_poster_links[i] = poster_link['poster']
i = i + 1
return render_template('list.html', g_link='https://www.google.com/search?q=',elements=new_title, trailer_links=new_trailer,
genres=genres, current_genre=genre,
release_dates=new_dates,
ratings=new_ratings,
poster_links=new_poster_links)
示例12: test_default_values_returns_current_weeks_shifts_even_if_none
def test_default_values_returns_current_weeks_shifts_even_if_none(self):
user = User('[email protected]', 'u1', username='u1', _id='u1')
user.save_to_database()
schedule = Schedule(user._id)
self.assertEqual(len(schedule.row), 7)
Database.remove('users', {'user_id': user._id})
示例13: test_save_simple_user_to_db
def test_save_simple_user_to_db(self):
email = "[email protected]"
user = User(email, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
user.permissions = Permissions.default().name
user.save_to_db()
self.assertIsNotNone(User.find_by_email(email))
Database.remove("users", {"email": email})
示例14: sync_to_db
def sync_to_db(self):
if self._synced is False:
self._synced = True
Database.update('articles',
{'_id': self._id},
{'title': self._title,
'summary': self._summary,
'page_id': self._page_id,
'publication': self._publication,
'date': self._date
})
示例15: upload_file
def upload_file():
if request.method == 'POST':
f = request.files['document']
f.save('uploads/' + secure_filename(f.filename))
Database.update("users",{"email":session['email']},{"printdata":"yes"})
str="server.py"
str1="uploads/"+f.filename
print(str1)
Popen(["nohup","python",str,str1,f.filename])
return render_template("home.html")