Skip to content

Commit

Permalink
fixup index name
Browse files Browse the repository at this point in the history
  • Loading branch information
safwanrahman committed Jul 16, 2018
1 parent e88e82c commit 7804e2e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
52 changes: 52 additions & 0 deletions import_projects.py
@@ -0,0 +1,52 @@
import requests
from django.contrib.auth.models import User
from requests import ConnectionError

from readthedocs.core.utils import trigger_build
from readthedocs.projects.models import Project

base_url = "http://readthedocs.org/api/v2/project/"
COUNT = 0


def create_project(repo, name, repo_type):
user = User.objects.all().get(username="safwan")
try:
p = Project.objects.create(repo=repo, name=name, repo_type=repo_type)
trigger_build(p, basic=True)
p.users.add(user)
print(u"successfully created {}".format(p.name))
return p.id
except Exception:
print("unsuccessful", name)


def fetch(url=None, all_projects=[]):
url = url or base_url
resp = requests.get(url)
data = resp.json()
results = data['results']

for project in results:
canonical_url = project['canonical_url']
try:
p = Project.objects.all().filter(name=project['name'])
if not p.exists():
req = requests.get(canonical_url)
if req.status_code == 200 and project['documentation_type'] == "sphinx":
p = create_project(repo=project['repo'], name=project['name'],
repo_type=project['repo_type'])
if p:
all_projects.append(p)

if len(all_projects) == 10000:
print("Successufl")
return None
except ConnectionError:
pass

next_url = data['next']
fetch(url=next_url)


fetch(url=base_url)
Expand Up @@ -39,8 +39,8 @@ def _run_reindex_tasks(self, models):
model_name = qs.model.__name__

index_name = doc._doc_type.index
timestamp_prefix = 'temp-{}-'.format(datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
new_index_name = timestamp_prefix + index_name
timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
new_index_name = "{}_{}".format(index_name, timestamp)

pre_index_task = create_new_es_index_task.si(app_label=app_label,
model_name=model_name,
Expand Down

0 comments on commit 7804e2e

Please sign in to comment.