-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Импорт публичных постов из основного клуба в dev/local среду #1212
Conversation
…/редактирования постав, завязал всё на `save`, чтобы было проще вешать триггеры для того же manticore, если будем внедрять. Не нравится 93 строчка ;(( Добавил описание в инфо для разрабов
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ну вроде бы норм
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Мне тоже ок, спасибо за скрипт!
Я добавил несколько мелких предложений для изменений. Прими, что считаешь нужным.
user, created = User.objects.get_or_create(slug=slug, defaults=defaults) | ||
|
||
return user, created |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user, created = User.objects.get_or_create(slug=slug, defaults=defaults) | |
return user, created | |
return User.objects.get_or_create(slug=slug, defaults=defaults) |
|
||
Sometimes you need fill saome posts/users data from real project. For this case you can use `import_posts_to_dev` command. | ||
|
||
Command fetch https://vas3k.club/feed.json and copy `is_public=True` posts to your database: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Command fetch https://vas3k.club/feed.json and copy `is_public=True` posts to your database: | |
Command fetch https://vas3k.club/feed.json and copy public posts to your database: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@igoose1 решил на мотив питона указать, всё же питонисты будут читать. точно надо просто public
указать?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trin4ik, по-твоему тоже ок.
split = author['url'].split('/') | ||
slug = split[-2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
split = author['url'].split('/') | |
slug = split[-2] | |
*_, slug, _ = author['url'].split('/') # takes SLUG from "https://vas3k.club/user/SLUG/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@igoose1 повторю, я в питоне на уровне фреймворков пару дней, в основном скрипты писал разовые. как скажешь. *_
-- крутая конструкция, почти влюбился
balance=10000, | ||
created_at=datetime.utcnow(), | ||
updated_at=datetime.utcnow(), | ||
membership_started_at=datetime.now(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
membership_started_at=datetime.now(), | |
membership_started_at=datetime.utcnow(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@igoose1 my bad, правлю
url = "https://vas3k.club/feed.json?page={}".format(x + 1) | ||
self.stdout.write("📁 {}".format(url)) | ||
req = urllib.request.Request(url) | ||
req.add_header('User-Agent', 'Mozilla/5.0') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Предлагаю поставить здесь отличимый User-Agent. На случай, если этот скрипт начнут абьюзить.
req.add_header('User-Agent', 'Mozilla/5.0') | |
req.add_header('User-Agent', 'poststodev') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@igoose1 исправил на posts-to-dev
data = json.load(response) | ||
for item in data['items']: | ||
# приватные нафиг | ||
if not (item['_club']['is_public']): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not (item['_club']['is_public']): | |
if not item['_club']['is_public']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@igoose1 php привычка, поправлю
Пушнул все замечания @igoose1 кроме доки, дока кмк для питонистов будет более понятно с |
@trin4ik, мне кажется, с is_public не так важно. Можно оставить любой вариант. В общем, по-моему, хороший PR. Такой скрипт я бы хотел видеть в репозитории. |
Ну, он, скрипт, есть у вас. меня беспокоит 93 строчка, из-за |
Хочу подбить поиск, мантикора смотрится вполне интересным вариантом. Для тестов столкнулся с тем. что не плохо бы иметь на локалке "живые" посты.
Накидал команду, которая парсит https://vas3k.club/feed.json, собирает там публичные посты (чтобы был полный текст, а не обрывки) и вставляет всё это добро в локальную базу.
Работает только на локальныъ/дев сборках, т.к.
p.s. никогда не работал с django, если где есть "понятийные" ошибки, буду рад, если укажите.