Created
May 26, 2021 09:40
-
-
Save wbarcovsky/ebd077e7024972bb51a1b74a88429cae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* eslint-disable */ | |
| const WebflowClass = require('../logic/integration/webflow/webflow'); | |
| const {get} = require('../utils/objects.js'); | |
| const db = require('../db'); | |
| const _ = require('underscore'); | |
| function capitalizeFirstLetter(string) { | |
| return string.charAt(0).toUpperCase() + string.slice(1); | |
| } | |
| const mapPlace = (place) => { | |
| let address = ''; | |
| if (get(place, 'address.city')) { | |
| address = `${get(place, 'address.city.type')}. ${get(place, 'address.city.name')}`; | |
| } | |
| if (get(place, 'address.settlement')) { | |
| address = `${get(place, 'address.settlement.type')}. ${get(place, 'address.settlement.name')}`; | |
| } | |
| return { | |
| Местоположение: address, | |
| Категория: capitalizeFirstLetter(get(place, 'category.name')), | |
| Изображение: `http://bel.cultreg.ru/uploads/${place.image.name}`, | |
| Ссылка: `http://bel.cultreg.ru/places/${place._id}/${place.sysName}`, | |
| Заголовок: place.name, | |
| }; | |
| }; | |
| const main = async () => { | |
| await db.init(); | |
| const lists = [ | |
| {id: '6093f71f31d70f291428b58e', name: 'Точки питания', places: [1947, 1912, 1948]}, | |
| {id: '6070665dbdfd19f53b5549af', name: 'Точки питания.2', places: [1947, 1912, 1948]}, | |
| { | |
| id: '607eea4c9cf69f7f0b79b1b8', name: 'Воинская слава', places: [ | |
| 27, 202, 1909, 1914, 445, 1759, 203, 1946, | |
| 1945, 1922, 1923, 1925, 1928, 1930, 1944, 257, 459, 1932, 1933, | |
| ], | |
| }, | |
| { | |
| id: '607eeaa86b482b70601aa72f', | |
| name: 'Экологический туризм', | |
| places: [241, 1941, 1942, 1943, 1955, 1954, 1949, 1972, 1915, 206, 195, 1950] | |
| }, | |
| {id: '607eeb6baf113a2043fd5c83', name: 'Спорт', places: [1974, 1973]}, | |
| {id: '607eeb05bfd78658bb4a25f8', name: 'Культурный туризм', places: [1916, 1917, 1641, 1951, 439]}, | |
| {id: '607e849a5dab6bccdbbce17f', name: 'Религиозный туризм', places: [1919, 1936, 1937, 1938, 1939, 1940]}, | |
| {id: '6093f441b99cb91cd2c589d4', name: 'Гостиницы', places: [1920, 1959, 1958, 1957, 1956, 1921]}, | |
| {id: '607064d66225e2059b5333e3', name: 'Гостиницы.2', places: [1920, 1959, 1958, 1957, 1956, 1921]}, | |
| {id: '607eea4c9cf69f7f0b79b1b8', name: 'События', articles: [139, 372, 513, 514]}, | |
| ]; | |
| const token = 'a629e727d45b9f056bef3db27da5f571f1886b42c6834537ec0d5b876d34e924'; | |
| const webflow = new WebflowClass(token); | |
| for (const list of lists) { | |
| const collInfo = await webflow.getCollectionInfo(list.id); | |
| await webflow.clearCollection(list.id); | |
| if (list.places) { | |
| for (const placeId of list.places) { | |
| const dbPlace = await db.actualPlaces.findOne({_id: placeId}); | |
| const placeData = mapPlace(dbPlace); | |
| const data = {_archived: false, _draft: false}; | |
| Object.keys(placeData).forEach(key => { | |
| const field = collInfo.fields.find(f => f.name === key); | |
| if (field) { | |
| data[field.slug] = placeData[key]; | |
| } | |
| }); | |
| console.log(await webflow.createCollectionItem(list.id, data)); | |
| } | |
| } | |
| } | |
| console.log(await webflow.getCollectionInfo('607eea4c9cf69f7f0b79b1b8')); | |
| console.log('DONE!'); | |
| process.exit(); | |
| }; | |
| main().catch(e => console.error(e)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment