Example #1
0
def add_webhooks(shop):
    customer = Customer.query.filter_by(shop=shop).first()
    shopify.Session.setup(api_key=api_key, secret=api_secret_key)
    session = shopify.Session(customer.shop, customer.code)
    shopify.ShopifyResource.activate_session(session)

    action = application.config['HTTPS'] + application.config[
        'HOST'] + "/webhook/product/create"
    sw = shopify.Webhook()
    sw.topic = 'products/create'
    sw.address: action
    sw.format = "json"
    sw.save()

    s = ScriptTag(sw.id, 'webhook-product-create', shop)
    db.session.add(s)
    db.session.commit()

    action = application.config['HTTPS'] + application.config[
        'HOST'] + "/webhook/product/delete"
    sw = shopify.Webhook()
    sw.topic = 'products/delete'
    sw.address: action
    sw.format = "json"
    sw.save()

    s = ScriptTag(sw.id, 'webhook-product-delete', shop)
    db.session.add(s)
    db.session.commit()

    action = application.config['HTTPS'] + application.config[
        'HOST'] + "/webhook/product/update"
    sw = shopify.Webhook()
    sw.topic = 'products/update'
    sw.address: action
    sw.format = "json"
    sw.save()

    s = ScriptTag(sw.id, 'webhook-product-update', shop)
    db.session.add(s)
    db.session.commit()

    action = application.config['HTTPS'] + application.config[
        'HOST'] + "/app/uninstalled"
    sw = shopify.Webhook()
    sw.topic = 'app/uninstalled'
    sw.address: action
    sw.format = "json"
    sw.save()

    s = ScriptTag(sw.id, 'webhook-app-uninstalled', shop)
    db.session.add(s)
    db.session.commit()

    return True
Example #2
0
def home(request, *args, **kwargs):
  shop_name = request.user.myshopify_domain
  print('++++++++++++++++++ activating webhook ++++++++++++++++++')
  webhook_shop_address = settings.APP_DOMAIN + '/app/uninstall_webhook_callback/'
  with request.user.session:
    webhook_status = 0
    webhook_shops = shopify.Webhook.find()
    if webhook_shops:
      for webhook_shop in webhook_shops:
        if webhook_shop.address == webhook_shop_address:
          webhook_status = 1
    if webhook_status == 0:
      print('++++++++++++++++++ saving webhook ++++++++++++++++++')
      webhook_shop = shopify.Webhook()
      webhook_shop.topic = 'app/uninstalled'
      webhook_shop.address = webhook_shop_address
      webhook_shop.format = 'json'
      webhook_shop.save()
      
    url = settings.APP_DOMAIN + settings.STATIC_URL + 'script/script.js'    
    shopify.ScriptTag(dict(event='onload', src=url)).save()


  items = Times.objects.filter(shop_name=shop_name).order_by('-id')
  item = {};
  if items:
    item = items[0]

  conf_items = TextConf.objects.filter(shop_name=shop_name).order_by('-id')
  conf_item = {};
  if conf_items:
    conf_item = conf_items[0]


  return render(request, "main_app/home.html", { "item": item, "conf": conf_item })
Example #3
0
    def create_webhook(self):
        """Create webhook for listening events for inventory adjustment, product and variant deletion."""
        def address(name):
            return f"https://{URL + reverse('shopify_app:' + name)}"

        try:
            webhooks = shopify.Webhook.find()
            if webhooks:
                for _ in webhooks:
                    _.destroy()
            webhook = shopify.Webhook()
            webhook.create({
                'topic': 'inventory_levels/update',
                'address': address('inventory_levels_update')
            })
            webhook.create({
                'topic': 'inventory_items/update',
                'address': address('inventory_items_update')
            })
            webhook.create({
                'topic': 'products/update',
                'address': address('products_update')
            })
            webhook.create({
                'topic': 'inventory_items/delete',
                'address': address('inventory_items_delete')
            })
            webhook.create({
                'topic': 'products/delete',
                'address': address('products_delete')
            })
        except Exception as e:
            print(e)
Example #4
0
def create_webhook(stores_obj):
    """
    Create a shop webhook and add to store.
    """
    try:
        session = shopify.Session(stores_obj.store_name, stores_obj.permanent_token)
        shopify.ShopifyResource.activate_session(session)
        topic = 'app/uninstalled'

        new_webhook = shopify.Webhook()
        new_webhook.address = settings.APP_URL + '/webhooks/'
        new_webhook.topic = topic

        # [shopify.Webhook.delete(x.id) for x in shopify.Webhook.find()]

        if new_webhook.save():
            Webhooks.objects.update_or_create(store__store_name=stores_obj.store_name,
                                              topic=topic,
                                              defaults={'webhook_id': new_webhook.attributes['id'],
                                                        'store': stores_obj,
                                                        'topic': topic})
        else:
            logger.error('Warning for {}. Webhook {} not saved properly!'.format(stores_obj.store_name, topic))

    except Exception as e:
        logger.error('Exception caught for {}. {}'.format(stores_obj.store_name, e))
def subscribe_webhooks(sender, **kwargs):
    hook = shopify.Webhook()
    hook.topic = "app/uninstalled"
    hook.address = settings.BASE_URL_SSL + "app-uninstalled"
    hook.format = "json"
    hook.save()
    if(hook.errors):
        logger.error(hook.errors.full_messages())
Example #6
0
def create_uninstall_webhook(shop, access_token):
    with shopify_session(shop, access_token):
        app_url = apps.get_app_config("shopify_app").APP_URL
        webhook = shopify.Webhook()
        webhook.topic = "app/uninstalled"
        webhook.address = "https://{host}/uninstall".format(host=app_url)
        webhook.format = "json"
        webhook.save()
Example #7
0
def register_hooks(request):
    shop_url = request.session.get('shopify')['shop_url']
    shop_url = urllib.quote(shop_url)
    logger.debug('Registering Webhooks for Shop: %s' % shop_url)
    webhook = shopify.Webhook()
    webhook.format = 'json'
    webhook.address = '%s/hook/order/%s/' % (APP_URL, shop_url)
    webhook.topic = 'orders/create'
    webhook.save()
    logger.debug(
        'Made webhook: %s:: format: %s, address: %s, topic: %s, errors %s' %
        (webhook, webhook.format, webhook.address, webhook.topic,
         webhook.errors.full_messages()))
    logger.debug('Webhook is valid %s' % webhook.is_valid())
    return redirect('/')
Example #8
0
    def get(self, request):
        state = request.GET.get('state', None)
        session_state = request.session.get('state', None)
        if not state or not session_state or state != session_state:
            return HttpResponseForbidden()
        params = {
            'shop': request.GET.get('shop', None),
            'code': request.GET.get('code', None),
            'timestamp': request.GET.get('timestamp', None),
            'signature': request.GET.get('signature', None),
            'state': request.GET.get('state', None),
            'hmac': request.GET.get('hmac', None),
        }
        session = shopify.Session(
            'https://%s.%s%s' %
            (request.GET.get('shop', None), settings.SHOPIFY_URL,
             settings.SHOPIFY_AUTHORIZE_SUFIX))

        session.setup(api_key=settings.SHOPIFY_API_KEY,
                      secret=settings.SHOPIFY_SECRET)
        try:
            token = session.request_token(params)
        except shopify.ValidationException:
            return HttpResponseForbidden()
        context = {}
        context["shop"] = request.GET.get('shop', None)
        context["api_key"] = settings.SHOPIFY_API_KEY

        shop = Shop.objects.filter(name=context["shop"])
        request.session['shop_name'] = request.GET.get('shop', None)
        request.session['shop_token'] = token
        if not shop:
            shop_obj = Shop(name=context["shop"], token=token)
            shop_obj.save()
            activate_shopify_session(request)
            webhook = shopify.Webhook()
            webhook.topic = "app/uninstalled"
            webhook.address = "https://app.roojet.com/uninstall/"
            webhook.format = "json"
            success = webhook.save()

        return render(request, self.template_name, context)
Example #9
0
def finalize():
    code = request.args.get('code')
    shop_name = request.args.get('shop')
    timestamp = request.args.get('timestamp')
    hmac = request.args.get('hmac')
    params = {
        'code': code,
        'timestamp': timestamp,
        'hmac': hmac,
        'shop': shop_name
    }
    api_version = app.config.get('SHOPIFY_API_VERSION')
    shopify.Session.setup(api_key=app.config['SHOPIFY_API_KEY'],
                          secret=app.config['SHOPIFY_API_SECRET'])
    session = shopify.Session(shop_name, api_version)
    token = session.request_token(params)

    try:
        merchant = Merchant.get(Merchant.shop_name == shop_name)

    except Merchant.DoesNotExist:
        merchant = Merchant()
        merchant.enable = False
        merchant.shop_name = shop_name

    merchant.token = token
    merchant.save()

    save_default_html(merchant)

    shop_short = shop_name.replace('.myshopify.com', '')

    need_webhooks = [
        {
            'url': 'https://{}/create_order/{}'.format(
                app.config.get('HOSTNAME'), shop_short),
            'topic': 'orders/create',
            'created': False
        },
        {
            'url': 'https://{}/uninstalled'.format(
                app.config.get('HOSTNAME')),
            'topic': 'app/uninstalled',
            'created': False
        },
    ]

    with shopify.Session.temp(shop_name, api_version, merchant.token):
        webhooks = shopify.Webhook.find()

        for webhook in webhooks:

            for need_webhook in need_webhooks:

                if webhook.topic == need_webhook.get('topic') and \
                        webhook.address == need_webhook.get('url'):
                    need_webhook.update({'created': True})

        for need_webhook in need_webhooks:

            if need_webhook.get('created'):
                continue

            app.logger.info('create webhook {}'.format(need_webhook.get('topic')))
            webhook = shopify.Webhook()
            webhook.topic = need_webhook.get('topic')
            webhook.address = need_webhook.get('url')
            webhook.format = 'json'
            webhook.save()
            pause_sdk(2)

        ecocart_script = shopify.ScriptTag()
        ecocart_script.event = 'onload'
        ecocart_script.src = 'https://{}/ecocart.js?shop_name={}'.format(
            app.config.get('HOSTNAME'), shop_name)
        ecocart_script.save()

    image_url = app.config.get('ECOCART_IMAGE_URL')
    e = Ecocart(image_url, merchant)
    e.install()

    if not app.config.get('CHARGE_ENABLE'):
        url = 'https://{}/admin/apps/{}'
        # редирект в админку
        return redirect(url.format(shop_name, app.config.get('SHOPIFY_API_KEY')))

    # подписка
    return_url = 'https://{}/activatecharge/{}'
    return_url = return_url.format(app.config.get('HOSTNAME'), shop_name)
    data_create = {
        'name': app.config.get('CHARGE_NAME'),
        'price': 0.5,
        'return_url': return_url,
        'test': app.config.get('CHARGE_TEST'),
    }
    url = create_application_charge(shop_name, token, data_create)

    return redirect(url)
Example #10
0
def createUninstallWebHook():
    webhook = shopify.Webhook()
    webhook.topic = 'app/uninstalled'
    webhook.address = settings.APP_DOMAINURL + '/webhook/'
    webhook.save()
    return webhook
Example #11
0
def home(request, *args, **kwargs):
    webhook_shop_address = settings.APP_DOMAIN + '/app/uninstall_webhook_callback/'
    with request.user.session:
        webhook_status = 0
        webhook_shops = shopify.Webhook.find()
        if webhook_shops:
            for webhook_shop in webhook_shops:
                if webhook_shop.address == webhook_shop_address:
                    webhook_status = 1
        if webhook_status == 0:
            webhook_shop = shopify.Webhook()
            webhook_shop.topic = 'app/uninstalled'
            webhook_shop.address = webhook_shop_address
            webhook_shop.format = 'json'
            webhook_shop.save()
    # getting the shop name and deleting the old customers' data
    shop_id = ''
    with request.user.session:
        shop = shopify.Shop.current()
        shop_id = str(shop.id)
    Customer.objects.filter(shop_name=shop_id).delete()
    Order.objects.filter(shop_name=shop_id).delete()
    #  getting the customers'data and orders' data from shopify API and saving in database.
    with request.user.session:
        customers = shopify.Customer.find()
        for customer in customers:
            for addr in customer.addresses:
                record = Customer(shop_name=shop_id,
                                  address1=addr.address1,
                                  address2=addr.address2,
                                  city=addr.city,
                                  country=addr.country,
                                  first_name=addr.first_name,
                                  addr_id=addr.id,
                                  last_name=addr.last_name,
                                  phone=addr.phone,
                                  province=addr.province,
                                  zip_code=addr.zip,
                                  province_code=addr.province_code,
                                  country_code=addr.country_code,
                                  email=customer.email,
                                  total_spent=customer.total_spent,
                                  created_at=customer.created_at,
                                  updated_at=customer.updated_at)
                record.save()

        orders = shopify.Order.find()
        length = len(orders)
        if length < 250:
            i = 0
        else:
            i = length - 250
        while i < length:
            items = ''
            for item in orders[i].line_items:
                items += item.name + ', '
            if not orders[i].shipping_address:
                for addr in orders[i].shipping_address:
                    record = Order(shop_name=shop_id,
                                   oid=orders[i].id,
                                   name=orders[i].name,
                                   number=orders[i].order_number,
                                   city=addr.city,
                                   province=addr.province,
                                   country=addr.country,
                                   items=items[:-2])
                    record.save()
            else:
                record = Order(shop_name=shop_id,
                               oid=orders[i].id,
                               name=orders[i].name,
                               number=orders[i].order_number,
                               items=items[:-2])
                record.save()
            i += 1

    # getting the customers for each shop and making csv and exporting
    customers = Customer.objects.filter(shop_name=shop_id)
    csv_url = settings.STATIC_ROOT + '/csv/' + shop_id + '.csv'
    city_list = []
    with open(csv_url, 'wb') as f:
        writer = csv.writer(f)
        writer.writerow([
            'shop_name', 'address1', 'address2', 'city', 'country',
            'first_name', 'addr_id', 'last_name', 'phone', 'province',
            'zip_code', 'province_code', 'country_code', 'email',
            'total_spent', 'created_at', 'updated_at', 'saved_at'
        ])
        for customer in customers:
            writer.writerow(get_list(customer))
            if customer.country_code == 'US':
                if not [customer.city, customer.province] in city_list:
                    city_list.append([customer.city, customer.province])
            else:
                if not [customer.city, customer.country] in city_list:
                    city_list.append([customer.city, customer.country])
    csv_name = shop_id + '.csv'

    # getting the weather information and saving in database with updating old data.

    # getting the number of customers for each duration(today, tomorrow, week)
    today_number = 0
    tomorrow_number = 0
    week_number = 0
    for customer in customers:
        city = customer.city
        city_s = ''
        if customer.country_code == 'US':
            city_s = customer.province
        else:
            city_s = customer.country
        try:
            weather_list = Weather.objects.filter(
                Q(city=city) & Q(city_sec=city_s))
            weather = weather_list[0]
            if weather.today_condition == 'sun':
                today_number += 1
            if weather.tomorrow_condition == 'sun':
                tomorrow_number += 1
            week_list = weather.week_condition.split(',')
            i = 0
            for we in week_list:
                we = we.strip()
                if we.find('sun') != -1:
                    i += 1
            week_number += i
        except:
            print '++++++++++++++++++ an error occupied'

    # return the values to template.
    return render(
        request, "main_app/installation.html", {
            'csv_name': csv_name,
            'today_number': today_number,
            'tomorrow_number': tomorrow_number,
            'week_number': week_number
        })
Example #12
0
    def finalize(self, **kw):
        shop_url = kw['shop']
        current_app = DefaultConfig()

        shopify.Session.setup(api_key=current_app.SHOPIFY_API_KEY,
                              secret=current_app.SHOPIFY_SHARED_SECRET)
        shopify_session = shopify.Session(shop_url, '2019-04')

        # todo : write it to another storage
        http.request.httprequest.session.shopify_obj = shopify_session

        token = shopify_session.request_token(kw)

        organizationEnv = http.request.env['shopify_app.shop']
        organization = organizationEnv.sudo().search([("url", "=", shop_url)])

        if organization['install_status'] == 'uninstalled':
            organization.write({'install_status': 'active'})

        if not organization:
            vals = {'url': shop_url, 'code': token}

            createdOrg = organization.sudo().create(vals)

            # Create company
            shopUrl = shop_url
            shopUrlemail = shop_url.split('.')[0] + '@gmail.com'
            companyModel = http.request.env['res.company']

            company = companyModel.sudo().search([("name", "=", shopUrl)])
            if not company:
                #create company
                vals = {
                    'logo': False,
                    'currency_id': 2,
                    'sequence': 10,
                    'favicon':
                    'AAABAAEAEBAAAAAAIAAGAgAAFgAAAIlQTkcNChoKAAAADUlIRFIAAAAQAAAAEAgGAAAAH/P/YQAAAc1JREFUeJyV0s+LzVEYBvDP+53vNUYzSZqFlbBgJUL5tWByJzaysZPJP2AhP+7SYhZXKZEtNRZKlqPUjEQTFmbhH5AosRPjTrr3zvdY3DO6ZiKe09k8z/u85+15T8i4c2xSraiRrBX24ih2YA3e4ileoJVSMjHbAAFT403tTtdgrbYbF3AcG5f1jK+YxbXFpYX5oYFhEzMNMVVvGh4c0mr/OIkb2OrveIfzA0U86i5VyojQav84gFvYnIu+4xXeoMQe7MMQtuDmUpU+R8R8iWFc7jO/x5XEdLAYRaGqqpHgNCaxKU95KaV0rsThHBi00AjxIKmcnekFNVVvLtRqa+52up0CtzGIekQcLHAE63ODl4npSjKRzTAx29DudiQe4nWmN2CsWBHam0K0UqpWR5eSIuIr5vvYbYXfV5VWO5eFtKy2++iiwIc+YmclrYsoVjWICJVqHXb20e8KzOmtDQ4F44F79eavqql6U/TOOA5l+huelYnn0dt5HSNoYjGFp/fGr3Xz+CXGsjaSGzzDXBl8wXXswii2436Ix3LiIfbhhN73ho/Zs1BCSulJRDTyC6O58Ey+K/EJFztL3bmyGBCn9l/9Y/L/gtVx/yd+Akefkiz2xrqJAAAAAElFTkSuQmCC',
                    'name': shopUrl,
                    'street': False,
                    'street2': False,
                    'city': False,
                    'state_id': False,
                    'zip': False,
                    'country_id': False,
                    'phone': False,
                    'email': False,
                    'website': False,
                    'vat': False,
                    'company_registry': False,
                    'parent_id': False
                }
                companyShop = companyModel.sudo().create(vals)
                companyId = companyShop.id
                # create user for the company
                user = http.request.env['res.users']

                userId = user.sudo().search([("login", "=", shopUrlemail)])
                if not userId:
                    vals = {
                        'is_published': False,
                        'company_ids': [[6, False, [companyId]]],
                        'company_id': companyId,
                        'active': True,
                        'lang': 'en_US',
                        'tz': 'Europe/Brussels',
                        'notification_type': 'email',
                        'odoobot_state': 'not_initialized',
                        'image_1920': False,
                        '__last_update': False,
                        'name': shopUrl,
                        'email': shopUrlemail,
                        'login': shopUrlemail,
                        'password': '******',
                        'action_id': False,
                        'alias_id': False,
                        'alias_contact': False,
                        'groups_id': [(6, 0, [1])]
                    }
                    createdUser = user.sudo().create(vals)
                    createdUserId = createdUser.id
                    # db = http.request.env.cr.dbname;
                    # uid = http.request.httprequest.session.authenticate(db, shopUrlemail, "token")
                    http.request.httprequest.session.shopify_token = token
                    http.request.httprequest.session.shopify_email = shopUrlemail

                    shopify.ShopifyResource.activate_session(shopify_session)
                    scrpt = shopify.ScriptTag(
                        dict(
                            event='onload',
                            src=
                            "https://c90bcfbe8e36.ngrok.io/shopify_app/static/src/js/shopify.js"
                        )).save()

                    # order create webhook
                    # orders / cancelled, orders / create, orders / fulfilled, orders / paid, orders / partially_fulfilled, orders / updated
                    weekhooks_response = shopify.Webhook(
                        dict(
                            topic="orders/create",
                            address=
                            "https://c90bcfbe8e36.ngrok.io/shopify_app/order_create",
                            format="json")).save()

                    weekhooks_response = shopify.Webhook(
                        dict(
                            topic="orders/updated",
                            address=
                            "https://c90bcfbe8e36.ngrok.io/shopify_app/order_update",
                            format="json")).save()

                    weekhooks_response = shopify.Webhook(
                        dict(
                            topic="orders/delete",
                            address=
                            "https://c90bcfbe8e36.ngrok.io/shopify_app/order_delete",
                            format="json")).save()

                    # checkout

                    weekhooks_response = shopify.Webhook(
                        dict(
                            topic="checkouts/create",
                            address=
                            "https://c90bcfbe8e36.ngrok.io/shopify_app/checkouts_create",
                            format="json")).save()
                    weekhooks_response = shopify.Webhook(
                        dict(
                            topic="checkouts/update",
                            address=
                            "https://c90bcfbe8e36.ngrok.io/shopify_app/checkouts_update",
                            format="json")).save()
                    weekhooks_response = shopify.Webhook(
                        dict(
                            topic="checkouts/delete",
                            address=
                            "https://c90bcfbe8e36.ngrok.io/shopify_app/checkouts_delete",
                            format="json")).save()
                    # uninstall app webhook
                    weekhooks_uninstall_response = shopify.Webhook(
                        dict(
                            topic="app/uninstalled",
                            address=
                            "https://c90bcfbe8e36.ngrok.io/shopify_app/app_uninstalled",
                            format="json")).save()
            else:
                # never run into this block of code,log for further usage
                x = 1
        #authenticate user and route to home
        user = http.request.env['res.users']

        shopUrlemail = shop_url.split('.')[0] + '@gmail.com'
        user = user.sudo().search([("login", "=", shopUrlemail)])

        shopUrlemail = shop_url.split('.')[0] + '@gmail.com'
        http.request.httprequest.session.shopify_email = shopUrlemail

        shopify.ShopifyResource.activate_session(shopify_session)
        weekhooks = shopify.Webhook.find()

        #todo : remove
        products = shopify.Product.find(page=2, limit=1)
        productsp1 = shopify.Product.find(page=1, limit=1)

        checkout = shopify.Checkout.find()
        checkoutc = shopify.Checkout(prefix_options='count').find()
        # checkoutc = shopify.Checkout(query_options={'cou
        # nt': ''}).find();
        checkoutc = shopify.Checkout.get('count')
        checkoutsx = shopify.Checkout.find(updated_at_min='2020-06-19')

        x = 1
        if not weekhooks:
            # order create webhook
            # orders / cancelled, orders / create, orders / fulfilled, orders / paid, orders / partially_fulfilled, orders / updated
            weekhooks_response = shopify.Webhook(
                dict(topic="orders/create",
                     address=
                     "https://c90bcfbe8e36.ngrok.io/shopify_app/order_create",
                     format="json")).save()

            weekhooks_response = shopify.Webhook(
                dict(topic="orders/updated",
                     address=
                     "https://c90bcfbe8e36.ngrok.io/shopify_app/order_update",
                     format="json")).save()

            weekhooks_response = shopify.Webhook(
                dict(topic="orders/delete",
                     address=
                     "https://c90bcfbe8e36.ngrok.io/shopify_app/order_delete",
                     format="json")).save()

            # checkout

            weekhooks_response = shopify.Webhook(
                dict(
                    topic="checkouts/create",
                    address=
                    "https://c90bcfbe8e36.ngrok.io/shopify_app/checkouts_create",
                    format="json")).save()
            weekhooks_response = shopify.Webhook(
                dict(
                    topic="checkouts/update",
                    address=
                    "https://c90bcfbe8e36.ngrok.io/shopify_app/checkouts_update",
                    format="json")).save()
            weekhooks_response = shopify.Webhook(
                dict(
                    topic="checkouts/delete",
                    address=
                    "https://c90bcfbe8e36.ngrok.io/shopify_app/checkouts_delete",
                    format="json")).save()
            # uninstall app webhook
            # weekhooks_uninstall_response = shopify.Webhook(dict(topic="app/uninstalled",
            #                                                     address="https://c90bcfbe8e36.ngrok.io/shopify_app/app_uninstalled",
            #                                                     format="json")).save()

        if user:
            db = http.request.env.cr.dbname
            uid = http.request.httprequest.session.authenticate(
                db, shopUrlemail, 'token')
            http.request.httprequest.session.shopify_token = token
            redirect = werkzeug.utils.redirect(
                'https://c90bcfbe8e36.ngrok.io/shopify_app/home')
            return redirect
Example #13
0
def home(request, *args, **kwargs):
    print '++++++++++++++++++ activating webhook ++++++++++++++++++'
    webhook_shop_address = 'https://9731e621.ngrok.io' + '/app/uninstall_webhook_callback/'
    with request.user.session:
        webhook_status = 0
        webhook_shops = shopify.Webhook.find()
        if webhook_shops:
            for webhook_shop in webhook_shops:
                if webhook_shop.address == webhook_shop_address:
                    webhook_status = 1
        if webhook_status == 0:
            print '++++++++++++++++++ saving webhook ++++++++++++++++++'
            webhook_shop = shopify.Webhook()
            webhook_shop.topic = 'app/uninstalled'
            webhook_shop.address = webhook_shop_address
            webhook_shop.format = 'json'
            webhook_shop.save()
    print '++++++++++++++++++++++++++ shopify store information ++++++++++++++++++++'
    shop_name = request.user.myshopify_domain
    print shop_name
    shop_id = ''
    with request.user.session:
        shop = shopify.Shop.current()
        shop_id = str(shop.id)
    print shop_id
    try:
        current_shop = AuthShop.objects.filter(shop_name=shop_name)[0]
        current_shop.shop_id = shop_id
        current_shop.save()
    except:
        print '++++++++++++++++++ current shop id error ++++++++++++++++++'
        pass
    try:
        current_info = Countnumber.objects.filter(
            shop_name=shop_name).order_by('-id')[0]
        sun_today_number = current_info.sun_today
        rain_today_number = current_info.rain_today
        wind_today_number = current_info.wind_today
        snow_today_number = current_info.snow_today
        sun_tomorrow_number = current_info.sun_tomorrow
        rain_tomorrow_number = current_info.rain_tomorrow
        wind_tomorrow_number = current_info.wind_tomorrow
        snow_tomorrow_number = current_info.snow_tomorrow
        sun_week_number = current_info.sun_week
        rain_week_number = current_info.rain_week
        wind_week_number = current_info.wind_week
        snow_week_number = current_info.snow_week
    except:
        sun_today_number = '0'
        rain_today_number = '0'
        wind_today_number = '0'
        snow_today_number = '0'
        sun_tomorrow_number = '0'
        rain_tomorrow_number = '0'
        wind_tomorrow_number = '0'
        snow_tomorrow_number = '0'
        sun_week_number = '0'
        rain_week_number = '0'
        wind_week_number = '0'
        snow_week_number = '0'

    csv_name = shop_id + '.csv'

    return render(
        request, "main_app/installation.html", {
            'csv_name': csv_name,
            'sun_today_number': sun_today_number,
            'rain_today_number': rain_today_number,
            'wind_today_number': wind_today_number,
            'snow_today_number': snow_today_number,
            'sun_tomorrow_number': sun_tomorrow_number,
            'rain_tomorrow_number': rain_tomorrow_number,
            'wind_tomorrow_number': wind_tomorrow_number,
            'snow_tomorrow_number': snow_tomorrow_number,
            'sun_week_number': sun_week_number,
            'rain_week_number': rain_week_number,
            'wind_week_number': wind_week_number,
            'snow_week_number': snow_week_number,
        })