from helpers import read_data, get_settings, package_translation import api settings = get_settings() article_map = read_data('article_map') locales = ['de', 'es', 'fr', 'ja', 'pt-br'] for article in article_map: url = '{}/articles/{}/translations/missing.json'.format( settings['src_root'], article) missing_locales = api.get_resource_list(url, list_name='locales', paginate=False) for locale in locales: if locale in missing_locales: # if translation missing in src, nothing to move continue print('Moving {} translation for article {}'.format(locale, article)) # get translation in src hc url = '{}/articles/{}/translations/{}.json'.format( settings['src_root'], article, locale) translation = api.get_resource(url) # create translation in dest hc url = '{}/articles/{}/translations.json'.format( settings['dst_root'], article_map[article]) payload = package_translation(translation) api.post_resource(url, payload) print('\nFinished moving translations.\n')
url = '{}/{}/articles/{}/votes.json'.format(settings['src_root'], settings['locale'], src_article) votes = api.get_resource_list(url) if not votes: print('- no votes found') continue for vote in votes: if last_sync < arrow.get(vote['created_at']): print('- adding vote {} to article {}'.format( vote['id'], dst_article)) if vote['value'] == -1: url = '{}/articles/{}/down.json'.format( settings['dst_root'], dst_article) else: url = '{}/articles/{}/up.json'.format(settings['dst_root'], dst_article) payload = { 'vote': { 'user_id': vote['user_id'], 'created_at': vote['created_at'] } } response = api.post_resource(url, payload, status=200) if response is False: print('Skipping vote {}'.format(vote['id'])) utc = arrow.utcnow() sync_dates['article_votes'] = utc.format() write_data(sync_dates, 'sync_dates')
from helpers import read_data, get_settings import api settings = get_settings() section_map = read_data('section_map') for section in section_map: dst_section = section_map[section] print('\nGetting subscriptions for section {}...'.format(section)) url = '{}/{}/sections/{}/subscriptions.json'.format(settings['src_root'], settings['locale'], section) subscriptions = api.get_resource_list(url) if not subscriptions: print('- no subscriptions found') continue for sub in subscriptions: print('- adding subscription {} to section {}'.format(sub['id'], dst_section)) url = '{}/sections/{}/subscriptions.json'.format(settings['dst_root'], dst_section) if sub['include_comments'] is True: payload = {'subscription': {'source_locale': settings['locale'], 'user_id': sub['user_id'], 'include_comments': True}} else: payload = {'subscription': {'source_locale': settings['locale'], 'user_id': sub['user_id']}} response = api.post_resource(url, payload) if response is False: print('Skipping subscription {}'.format(sub['id']))
url = '{}/{}/sections/{}/articles.json'.format(settings['src_root'], settings['locale'], section) articles = api.get_resource_list(url) for src_article in articles: if str(src_article['id']) in exceptions: print('{} is an exception. Skipping...'.format(src_article['id'])) continue if last_sync < arrow.get(src_article['created_at']): print('- adding article {} to destination section {}'.format( src_article['id'], dst_section)) src_article['author_id'] = verify_author(src_article['author_id'], settings['team_user']) url = '{}/{}/sections/{}/articles.json'.format( settings['dst_root'], settings['locale'], dst_section) payload = package_article(src_article) new_article = api.post_resource(url, payload) if new_article is False: print('Skipping article {}'.format(src_article['id'])) continue article_map[str(src_article['id'])] = new_article['id'] continue if last_sync < arrow.get(src_article['edited_at']): print('- updating article {} in destination section {}'.format( src_article['id'], dst_section)) dst_article = article_map[str(src_article['id'])] url = '{}/articles/{}/translations/{}.json'.format( settings['dst_root'], dst_article, settings['locale']) payload = package_article(src_article, put=True) response = api.put_resource(url, payload) if response is False: print('Skipping article {}'.format(src_article['id']))
settings['locale'], src_article) comments = api.get_resource_list(url) if not comments: print('- no comments found') continue for src_comment in comments: if src_comment['body'] == '': continue if last_sync < arrow.get(src_comment['created_at']): print('- adding new comment {} to article {}'.format( src_comment['id'], dst_article)) url = '{}/articles/{}/comments.json'.format( settings['dst_root'], dst_article) payload = package_comment(src_comment) new_comment = api.post_resource(url, payload) if new_comment is False: print('Skipping comment {}'.format(src_comment['id'])) continue comment_map[str(src_comment['id'])] = new_comment['id'] comment_article_map[str(src_comment['id'])] = src_article continue if last_sync < arrow.get(src_comment['updated_at']): print('- updating comment {} in article {}'.format( src_comment['id'], dst_article)) dst_comment = comment_map[str(src_comment['id'])] url = '{}/articles/{}/comments/{}.json'.format( settings['dst_root'], dst_article, dst_comment) payload = package_comment(src_comment, put=True) response = api.put_resource(url, payload) if response is False: