def __init__(self): super().__init__() self.user = User() self.post = Post()
__author__ = 'hashbanger' from models.post import Post from database import Database Database.initialize() post = Post(123, 'prashant', 'some title', 'some content') post.save_to_mongo() post.get_from_mongo()
from models.post import Post from database import Database from menu import Menu from models.blog import Blog Database.initialize() post = Post(blog_id="000", title="Festival", content="Some event had been organige", author='Annn') post.save_to_mongo() print(post) posts = Post.from_blog("123") for post in posts: print(post)
from database import Database from models.post import Post Database.initialize() post = Post(blog_id="123", title="Another great post", content="This is some simple content", author="amefo") post.save_to_mongo()
def do_authorize_stuff(): post = Post(1) return self.pundit.authorize(post)
from models.post import Post from src.database import Database Database.initialize() post = Post("title", "onettad", "asdss") print(post.content)
def update_post(self): post = Post(id=1, userId=1, title="Post Title Updated", body=fake.text()) update_post(self, post)
def post(self): args = PostParser.parse_args() postData = Post(title=args['title'], content=args['content']) postData.save() return json.loads(postData.to_json())
from database import Database from models.post import Post __author__ = "jbarry1506" Database.initialize() post = Post() """ import pymongo uri = "mongodb://127.0.0.1:27017" client = pymongo.MongoClient(uri) database = client['bodyVaultWeb'] collection = database['users'] users = [user for user in collection.find({})] print(users) """
def receive(self, mail_message): try: id = self.get_id(mail_message) if not id: return slug = Slug.query(Slug.slug == id).get() if not slug: log_error('Invalid slug', 'Found no slug for id %s', id) return body_text, body_html = self.get_bodies(mail_message) raw_mail = RawMail(subject=mail_message.subject, sender=mail_message.sender, slug=id, date=slug.date, text=body_text, html=body_html) raw_mail.put() post = Post.query(Post.date == slug.date).get() is_new_post = post is None if is_new_post: post = Post(date=slug.date, source='email', has_images=False) #Now let's try parsing it into a good post... if body_html: post_text = strip_html( body_html ) #Prefer html because then we don't get linebreak issues logging.info('Parsing post from html') else: post_text = body_text logging.info('Parsing post from plain text') if not post_text: raise Exception( 'No plain text body in email, html body can\'t be parsed yet!' ) try: email_index = post_text.index('post+%s@' % id) post_text = post_text[:email_index] newline_index = post_text.rstrip().rindex('\n') post_text = post_text[:newline_index].strip() except: logging.info('Failed to remove all crap from post') #Strip 'Sent from my iPhone' if it's there. There are probably endless other Sent from #we could handle, but hey, I have an iPhone so that's the one I care about... post_text = re.sub('\s*Sent from my iPhone\s*$', '', post_text) post_text = post_text.rstrip() if post.text: post.text = post.text.encode( "UTF-8" ) + '\r\n\r\n' + Post.seperator + '\r\n\r\n' + post_text else: post.text = post_text.encode("UTF-8") self.process_attachments(mail_message, post) post.put() if is_new_post: counter = PostCounter.get() counter.increment(post.date.year, post.date.month) except: log_error('Failed to parse incoming email', traceback.format_exc(6))
db = sqlite3.connect('.data/db.sqlite') db.row_factory = make_dicts cur = db.cursor() User.create_table(cur) Post.create_table(cur) users = [ User("Ford", "*****@*****.**", "12345"), User("Arthur", "*****@*****.**", "12345"), ] posts = [ Post(content="Hi!", author_id="*****@*****.**"), Post(content="Don't destroy the earth please!", author_id="*****@*****.**"), ] for user in users: user.insert(cur) for post in posts: post.insert(cur) db.commit() print("The following users has been inserted into the DB" " (all the passwords are 12345):") for user in users:
from models.post import Post __author__ = 'swirth' post = Post("Post1 title", "Post1 content", "Post1 author") post2 = Post("Post2 title", "Post2 content", "Post2 author") print(post.content) print(post2.content)
from models.user import User from models.post import Post from models.comment import Comment from models.post_like import PostLike from models.log import Log from models.topic import Topic u1 = User() u1.username = '******' u1.email = '*****@*****.**' u1.fullname = 'James Bond' u1.password = '******' print('-------------- U1 -------------') u1.save() print(u1) p1 = Post() p1.path = 'this is path' p1.user_id = u1.id p1.description = 'this is description' p1.save() print(p1) c1 = Comment() c1.text = 'this is the first comment ever' c1.user_id = u1.id c1.post_id = p1.id c1.save() print(c1) lk1 = PostLike() lk1.post_id = p1.id lk1.user_id = u1.id lk1.save()
def create_post(self, title='', content=''): new_post = Post(title, content) self.posts.append(new_post)
# Language(lang_name="English"), # Language(lang_name="Spanish"), # Language(lang_name="French"), # Language(lang_name="Arabic"), # Language(lang_name="Mandarin"), # Language(lang_name="Hebrew") # ] list_posts = [ Post( title="Help me with my English", level= 1, dialect="American", is_offer=False, image="a", availability="I am available on Wednesday afternoons", description="I would like to improve my English! I can teach you Spanish", user_id=1, language_id=1 ), Post( #language_name="Spanish", title="Spanish lessons needed", level= 2, dialect="Argentinian", is_offer=False, image="a", availability="I can only do classes on the weekend", description="I'm moving to Buenos Aires soon and need to brush up on my Spanish!",
def new_post(self, title, content, date=datetime.datetime.utcnow()): post = Post(self._id, title, content, self.author, date) post.save_to_mongo()
from typing import List, Any from database import Database from models.post import Post #call to ensure their is connection Database.initialize() post = Post(blog_id="56", title="festival", content="today was blessing", author="joshua", date="2345678") p = Database.show() for i in p: print(i)
from database import Database from models.post import Post Database.initialize() post = Post("Post1 title", "Post1 content", "Post1 author") print(post.content) print(post.author)
# create new images from api images images = [] for image in api_images: image = Image(url=image['webformatURL'], uploader=users[randrange(len(users))], height=image['webformatHeight'], width=image['webformatWidth']) images.append(image) # for each user, add all uploaded images to posts, each post no more than 3 entries long for user in users: if user.uploaded_images: i = 0 while i < len(user.uploaded_images): entries = [] pos = 0 while pos < randrange(1, 4) and i < len(user.uploaded_images): entry = Entry(image=user.uploaded_images[i], caption=f'Caption {pos}', position=pos) entries.append(entry) pos += 1 i += 1 post = Post(title='New Post', creator=user, post_entries=entries) post.save() print(post.creator, post.post_entries) db.session.commit()