<commit_before>"""Simple social networking _thing_ to show you code snippets"""

__author__ = '<NAME>'

import datetime

from peewee import *
from flask.ext.login import UserMixin
from flask.ext.bcrypt import generate_password_hash

DATABASE = SqliteDatabase('snippetshare.db')

class User(UserMixin, Model):
	username = CharField(unique=True)
	password = CharField(max_length=100)
	joined_at = DateTimeField(default=datetime.datetime.now)
	is_admin = BooleanField(default=False)

	class Meta:
		database = DATABASE
		order_by = ('-joined_at',)

	def get_posts(self):
		return Post.select().where(Post.user == self)

	def get_stream(self):
		return Post.select().where(
			(Post.user << self.get_following()) |
			(Post.user == self)
		)

	def get_following(self):
		return (
			User.select().join(
				Relationship, on=Relationship.to_user
			).where(
				Relationship.from_user == self
			)
		)

	def get_followers(self):
		return (
			User.select().join(
				Relationship, on=Relationship.from_user
			).where(
				Relationship.to_user == self
			)
		)

	@classmethod
	def create_user(cls, username, password, admin=False):
		try:
			cls.create(
				username=username,
				password=generate_password_hash(password),
				is_admin=admin
			)
		except IntegrityError:
			raise ValueError("User already exists.")

class Post(Model):
	timestamp = DateTimeField(default=datetime.datetime.now)
	user = ForeignKeyField(
		rel_model=User,
		related_name='posts'
	)
	content = TextField()
	language = TextField()
	display_language = TextField()

	class Meta:
		database = DATABASE
		order_by = ('-timestamp',)

class Relationship(Model):
	from_user = ForeignKeyField(
		User,
		related_name='relationships'
	)
	to_user = ForeignKeyField(
		User,
		related_name='related_to'
	)

	class Meta:
		database = DATABASE
		indexes = (
			(('from_user', 'to_user'), True)
		)

def initialize():
	DATABASE.connect()
	DATABASE.create_tables([User, Post, Relationship], safe=True)
	DATABASE.close()<commit_msg>fixed error in tuple<commit_after>"""Simple social networking _thing_ to show you code snippets"""

__author__ = '<NAME>'

import datetime

from peewee import *
from flask.ext.login import UserMixin
from flask.ext.bcrypt import generate_password_hash

DATABASE = SqliteDatabase('snippetshare.db')

class User(UserMixin, Model):
	username = CharField(unique=True)
	password = CharField(max_length=100)
	joined_at = DateTimeField(default=datetime.datetime.now)
	is_admin = BooleanField(default=False)

	class Meta:
		database = DATABASE
		order_by = ('-joined_at',)

	def get_posts(self):
		return Post.select().where(Post.user == self)

	def get_stream(self):
		return Post.select().where(
			(Post.user << self.get_following()) |
			(Post.user == self)
		)

	def get_following(self):
		return (
			User.select().join(
				Relationship, on=Relationship.to_user
			).where(
				Relationship.from_user == self
			)
		)

	def get_followers(self):
		return (
			User.select().join(
				Relationship, on=Relationship.from_user
			).where(
				Relationship.to_user == self
			)
		)

	@classmethod
	def create_user(cls, username, password, admin=False):
		try:
			cls.create(
				username=username,
				password=generate_password_hash(password),
				is_admin=admin
			)
		except IntegrityError:
			raise ValueError("User already exists.")

class Post(Model):
	timestamp = DateTimeField(default=datetime.datetime.now)
	user = ForeignKeyField(
		rel_model=User,
		related_name='posts'
	)
	content = TextField()
	language = TextField()
	display_language = TextField()

	class Meta:
		database = DATABASE
		order_by = ('-timestamp',)

class Relationship(Model):
	from_user = ForeignKeyField(
		User,
		related_name='relationships'
	)
	to_user = ForeignKeyField(
		User,
		related_name='related_to'
	)

	class Meta:
		database = DATABASE
		indexes = (
			(('from_user', 'to_user'), True),
		)

def initialize():
	DATABASE.connect()
	DATABASE.create_tables([User, Post, Relationship], safe=True)
	DATABASE.close()
{'fraction_non_alphanumeric': 0.12105263157894737, 'fraction_numerical': 0.0015037593984962407, 'mean_word_length': 4.527700831024931, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3894847', 'n_tokens_mistral': 1508, 'n_tokens_neox': 1333, 'n_words': 276}