Tuesday, December 26, 2023

Six Essential Principles of Success in Trading

Six Essential Principles of Success in Trading

Success in trading is not just about luck or intuition; it involves a systematic approach grounded in solid principles. Here are six essential principles to guide you on your trading journey:

1. Information

Having a solid grasp of relevant knowledge is crucial. It’s important to stay informed and up-to-date on the latest developments in your field. In trading, this means keeping abreast of market news, trends, and financial data.

2. Planning

Strategic preparation sets the foundation. Planning helps you identify your goals, develop a roadmap to achieve them, and stay on track. A well-thought-out trading plan includes risk management strategies, entry and exit points, and criteria for evaluating trades.

3. Timing

Precision in execution is essential. Timing is critical in achieving success. Knowing when to act and when to wait can make all the difference. This involves understanding market cycles, recognizing patterns, and being patient enough to wait for the right opportunities.

4. Practice

Consistent rehearsal is paramount. Practice helps you hone your skills, build confidence, and prepare for success. Simulated trading, also known as paper trading, can be an effective way to practice without risking real money.

5. Patience

Endurance through challenges is indispensable. Patience is key to overcoming obstacles and persevering through difficult times. Markets can be unpredictable, and having the patience to stick to your plan is essential for long-term success.

6. Results

The culmination of efforts and dedication. Results are the ultimate measure of success. They reflect the hard work, dedication, and perseverance that went into achieving your goals. Regularly review your trading performance to understand what’s working and what needs improvement.

Remember, success is not just about achieving your goals, but also about the journey you take to get there. Keep these principles in mind and you’ll be well on your way to achieving your dreams!

Sunday, September 3, 2023

Automating Data Entry in Tally with PowerShell and Windows Forms

Automating Data Entry in Tally with PowerShell and Windows Forms

Automation can significantly enhance productivity by eliminating repetitive tasks, and PowerShell, combined with Windows Forms, is a powerful tool for such purposes. In this blog post, we'll explore a PowerShell script designed to automate data entry into a form, using data from a CSV file. This script leverages the System.Windows.Forms namespace to simulate keystrokes for data input.

Overview of the Script

The script reads data from a CSV file and simulates keyboard input to enter the data into a form. It follows these steps:

  • Loads the necessary Windows Forms assembly.
  • Reads data from the CSV file.
  • Uses SendKeys to simulate keystrokes for each record in the CSV.

The Script

[void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
Start-Sleep -Seconds 5
Import-Csv C:\Users\ersan\OneDrive\Documents\Data.csv | foreach {
    $_.Date
    [System.Windows.Forms.SendKeys]::SendWait("{F2}")
    [System.Windows.Forms.SendKeys]::SendWait($_.Date)
    [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
    Start-Sleep -Seconds 1
    [System.Windows.Forms.SendKeys]::SendWait($_.VoucherType)
    [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
    Start-Sleep -Seconds 1
    [System.Windows.Forms.SendKeys]::SendWait($_.CashType)
    [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
    Start-Sleep -Seconds 1
    [System.Windows.Forms.SendKeys]::SendWait($_.Amount)
    [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
    Start-Sleep -Seconds 1
    [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
    [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
    [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
    Start-Sleep -Seconds 1
}

Step-by-Step Explanation

Loading Windows Forms Assembly

[void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')

This line loads the System.Windows.Forms assembly, which is required to use the SendKeys class for simulating keyboard input.

Initial Delay

Start-Sleep -Seconds 5

A 5-second delay allows you to switch to the target application where data entry will occur.

Importing the CSV File

Import-Csv C:\Users\ersan\OneDrive\Documents\Data.csv | foreach {
    ...
}

This line imports the CSV file located at the specified path. Each row in the CSV file is processed in the foreach loop.

Simulating Keystrokes

[System.Windows.Forms.SendKeys]::SendWait("{F2}")
[System.Windows.Forms.SendKeys]::SendWait($_.Date)
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
Start-Sleep -Seconds 1
  • SendWait("{F2}"): Simulates pressing the F2 key.
  • SendWait($_.Date): Simulates typing the date from the CSV file.
  • SendWait("{ENTER}"): Simulates pressing the Enter key.
  • Start-Sleep -Seconds 1: Adds a delay to ensure the application processes the input.

The same pattern is repeated for VoucherType, CashType, and Amount fields.

Final Enter Key Presses

[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
Start-Sleep -Seconds 1

Additional Enter key presses may be required to complete the form submission or move to the next field.

Customizing the Script

Here are some ways you can customize the script:

  • CSV File Path: Update the path to your CSV file in the Import-Csv cmdlet.
  • Field Names: Ensure that the field names in the script (Date, VoucherType, CashType, Amount) match the column headers in your CSV file.
  • Delays: Adjust Start-Sleep durations based on the responsiveness of your target application.

Conclusion

This PowerShell script provides a simple yet effective way to automate data entry tasks. By leveraging the System.Windows.Forms namespace, you can simulate keystrokes and streamline repetitive data entry processes. Customizing the script to suit your specific needs can save time and reduce errors in data entry.

Feel free to adapt this script to your requirements, and happy automating!

Wednesday, August 2, 2023

Post to send whatsapp messages

[void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') Import-Csv C:\Users\ersan\OneDrive\Documents\SamplePS.csv | foreach { $_.File [system.Diagnostics.Process]::Start("chrome","https://wa.me/"+$_.Url+"?text=JSRM") Start-Sleep -Seconds 10 [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE}") [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE}") [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE}") [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE}") Start-Sleep -Seconds 1 [System.Windows.Forms.SendKeys]::SendWait("+{TAB}") [System.Windows.Forms.SendKeys]::SendWait("{ENTER}") Start-Sleep -Seconds 1 [System.Windows.Forms.SendKeys]::SendWait("{DOWN}") [System.Windows.Forms.SendKeys]::SendWait("{ENTER}") Start-Sleep -Seconds 2 [System.Windows.Forms.SendKeys]::SendWait("C:\Users\ersan\Downloads\ilovepdf_extracted-pages1\"+$_.File) Start-Sleep -Seconds 2 [System.Windows.Forms.SendKeys]::SendWait("{ENTER}") Start-Sleep -Seconds 4 [System.Windows.Forms.SendKeys]::SendWait("{TAB}") [System.Windows.Forms.SendKeys]::SendWait("{TAB}") [System.Windows.Forms.SendKeys]::SendWait("{TAB}") [System.Windows.Forms.SendKeys]::SendWait("{ENTER}") }

Friday, June 23, 2023

Reliance Company

Network 18
Football sports development limited
Reliance Eros Productions LLP
Hathway Cable & Datacom Limited
Den Networks Limited
Reliance Industrial Infrastructure Limited
Hathway Bhawani Cabletel & Datacom Limited
Reliance Jio Infocomm Limited
Jio Platforms Limited
Reliance Retail Limited
Reliance Petroleum Limited
Jio Payments Bank Limited
Mumbai Indians
Alok Industries Limited
Reliance Foundation
Mukesh Ambani Business List
Petro Chemical Business
Telecom Business
Agricultural Business
E-Commerce Business
Digital Media and Broadcasting Business
Online Service Business
Supermarket Chain Business
Reliance Digita
Reliance Fresh
Reliance Smart Bazar
Reliance Digital
Reliance Retail
Reliance trends
Ajio

Thursday, May 18, 2023

Nifty 500 List

360 ONE WAM Ltd. 3M India Ltd. ABB India Ltd. ACC Ltd. AIA Engineering Ltd. APL Apollo Tubes Ltd. AU Small Finance Bank Ltd. Aarti Drugs Ltd. Aarti Industries Ltd. Aavas Financiers Ltd. Abbott India Ltd. Adani Enterprises Ltd. Adani Green Energy Ltd. Adani Ports and Special Economic Zone Ltd. Adani Power Ltd. Adani Total Gas Ltd. Adani Transmission Ltd. Adani Wilmar Ltd. Aditya Birla Capital Ltd. Aditya Birla Fashion and Retail Ltd. Aegis Logistics Ltd. Aether Industries Ltd. Affle (India) Ltd. Ajanta Pharmaceuticals Ltd. Alembic Pharmaceuticals Ltd. Alkem Laboratories Ltd. Alkyl Amines Chemicals Ltd. Amara Raja Batteries Ltd. Amber Enterprises India Ltd. Ambuja Cements Ltd. Angel One Ltd. Anupam Rasayan India Ltd. Apar Industries Ltd. Apollo Hospitals Enterprise Ltd. Apollo Tyres Ltd. Aptus Value Housing Finance India Ltd. Archean Chemical Industries Ltd. Asahi India Glass Ltd. Ashok Leyland Ltd. Asian Paints Ltd. Aster DM Healthcare Ltd. Astral Ltd. Atul Ltd. Aurobindo Pharma Ltd. Avanti Feeds Ltd. Avenue Supermarts Ltd. Axis Bank Ltd. BASF India Ltd. BEML Ltd. BLS International Services Ltd. BSE Ltd. Bajaj Auto Ltd. Bajaj Finance Ltd. Bajaj Finserv Ltd. Bajaj Holdings & Investment Ltd. Balaji Amines Ltd. Balkrishna Industries Ltd. Balrampur Chini Mills Ltd. Bandhan Bank Ltd. Bank of Baroda Bank of India Bank of Maharashtra Bata India Ltd. Bayer Cropscience Ltd. Berger Paints India Ltd. Bharat Dynamics Ltd. Bharat Electronics Ltd. Bharat Forge Ltd. Bharat Heavy Electricals Ltd. Bharat Petroleum Corporation Ltd. Bharti Airtel Ltd. Bikaji Foods International Ltd. Biocon Ltd. Birla Corporation Ltd. Birlasoft Ltd. Blue Dart Express Ltd. Blue Star Ltd. Bombay Burmah Trading Corporation Ltd. Borosil Renewables Ltd. Bosch Ltd. Brigade Enterprises Ltd. Brightcom Group Ltd. Britannia Industries Ltd. C.E. Info Systems Ltd. CCL Products (I) Ltd. CESC Ltd. CG Power and Industrial Solutions Ltd. CRISIL Ltd. CSB Bank Ltd. Campus Activewear Ltd. Can Fin Homes Ltd. Canara Bank Capri Global Capital Ltd. Carborundum Universal Ltd. Castrol India Ltd. Ceat Ltd. Central Bank of India Central Depository Services (India) Ltd. Century Plyboards (India) Ltd. Century Textile & Industries Ltd. Cera Sanitaryware Ltd Chalet Hotels Ltd. Chambal Fertilizers & Chemicals Ltd. Chemplast Sanmar Ltd. Cholamandalam Financial Holdings Ltd. Cholamandalam Investment and Finance Company Ltd. Cipla Ltd. City Union Bank Ltd. Clean Science and Technology Ltd. Coal India Ltd. Cochin Shipyard Ltd. Coforge Ltd. Colgate Palmolive (India) Ltd. Computer Age Management Services Ltd. Container Corporation of India Ltd. Coromandel International Ltd. Craftsman Automation Ltd. CreditAccess Grameen Ltd. Crompton Greaves Consumer Electricals Ltd. Cummins India Ltd. Cyient Ltd. DCM Shriram Ltd. DLF Ltd. Dabur India Ltd. Dalmia Bharat Ltd. Data Patterns (India) Ltd. Deepak Fertilisers & Petrochemicals Corp. Ltd. Deepak Nitrite Ltd. Delhivery Ltd. Delta Corp Ltd. Devyani International Ltd. Divi's Laboratories Ltd. Dixon Technologies (India) Ltd. Dr. Lal Path Labs Ltd. Dr. Reddy's Laboratories Ltd. E.I.D. Parry (India) Ltd. EIH Ltd. EPL Ltd. Easy Trip Planners Ltd. Eicher Motors Ltd. Elgi Equipments Ltd. Emami Ltd. Endurance Technologies Ltd. Engineers India Ltd. Equitas Small Finance Bank Ltd. Eris Lifesciences Ltd. Escorts Kubota Ltd. Exide Industries Ltd. FDC Ltd. FSN E-Commerce Ventures Ltd. Federal Bank Ltd. Fertilisers and Chemicals Travancore Ltd. Fine Organic Industries Ltd. Finolex Cables Ltd. Finolex Industries Ltd. Firstsource Solutions Ltd. Five-Star Business Finance Ltd. Fortis Healthcare Ltd. G R Infraprojects Ltd. GAIL (India) Ltd. GMM Pfaudler Ltd. GMR Airports Infrastructure Ltd. Galaxy Surfactants Ltd. Garware Technical Fibres Ltd. General Insurance Corporation of India Gland Pharma Ltd. Glaxosmithkline Pharmaceuticals Ltd. Glenmark Pharmaceuticals Ltd. Global Health Ltd. Go Fashion (India) Ltd. Godfrey Phillips India Ltd. Godrej Agrovet Ltd. Godrej Consumer Products Ltd. Godrej Industries Ltd. Godrej Properties Ltd. Granules India Ltd. Graphite India Ltd. Grasim Industries Ltd. Great Eastern Shipping Co. Ltd. Greenpanel Industries Ltd. Grindwell Norton Ltd. Gujarat Alkalies & Chemicals Ltd. Gujarat Ambuja Exports Ltd. Gujarat Fluorochemicals Ltd. Gujarat Gas Ltd. Gujarat Narmada Valley Fertilizers and Chemicals Ltd. Gujarat Pipavav Port Ltd. Gujarat State Fertilizers & Chemicals Ltd. Gujarat State Petronet Ltd. H.E.G. Ltd. HCL Technologies Ltd. HDFC Asset Management Company Ltd. HDFC Bank Ltd. HDFC Life Insurance Company Ltd. HFCL Ltd. HLE Glascoat Ltd. Happiest Minds Technologies Ltd. Havells India Ltd. Hero MotoCorp Ltd. Hikal Ltd. Hindalco Industries Ltd. Hinduja Global Solutions Ltd. Hindustan Aeronautics Ltd. Hindustan Copper Ltd. Hindustan Petroleum Corporation Ltd. Hindustan Unilever Ltd. Hindustan Zinc Ltd. Hitachi Energy India Ltd. Home First Finance Company India Ltd. Honeywell Automation India Ltd. Housing & Urban Development Corporation Ltd. Housing Development Finance Corporation Ltd. ICICI Bank Ltd. ICICI Lombard General Insurance Company Ltd. ICICI Prudential Life Insurance Company Ltd. ICICI Securities Ltd. IDBI Bank Ltd. IDFC First Bank Ltd. IDFC Ltd. IFB Industries Ltd. IIFL Finance Ltd. IRB Infrastructure Developers Ltd. ITC Ltd. ITI Ltd. India Cements Ltd. Indiabulls Housing Finance Ltd. Indiabulls Real Estate Ltd. Indiamart Intermesh Ltd. Indian Bank Indian Energy Exchange Ltd. Indian Hotels Co. Ltd. Indian Oil Corporation Ltd. Indian Overseas Bank Indian Railway Catering And Tourism Corporation Ltd. Indian Railway Finance Corporation Ltd. Indigo Paints Ltd. Indraprastha Gas Ltd. Indus Towers Ltd. IndusInd Bank Ltd. Infibeam Avenues Ltd. Info Edge (India) Ltd. Infosys Ltd. Ingersoll Rand (India) Ltd. Intellect Design Arena Ltd. InterGlobe Aviation Ltd. Ipca Laboratories Ltd. J.B. Chemicals & Pharmaceuticals Ltd. J.K. Cement Ltd. JBM Auto Ltd. JK Lakshmi Cement Ltd. JK Paper Ltd. JM Financial Ltd. JSW Energy Ltd. JSW Steel Ltd. Jamna Auto Industries Ltd. Jindal Stainless Ltd. Jindal Steel & Power Ltd. Jindal Worldwide Ltd. Jubilant Foodworks Ltd. Jubilant Ingrevia Ltd. Jubilant Pharmova Ltd. Justdial Ltd. Jyothy Labs Ltd. K.P.R. Mill Ltd. KEI Industries Ltd. KNR Constructions Ltd. KPIT Technologies Ltd. KRBL Ltd. KSB Ltd. Kajaria Ceramics Ltd. Kalpataru Power Transmission Ltd. Kalyan Jewellers India Ltd. Kansai Nerolac Paints Ltd. Karur Vysya Bank Ltd. Kec International Ltd. Kennametal India Ltd. Keystone Realtors Ltd. Kfin Technologies Ltd. Kotak Mahindra Bank Ltd. Krishna Institute of Medical Sciences Ltd. L&T Finance Holdings Ltd. L&T Technology Services Ltd. LIC Housing Finance Ltd. LTIMindtree Ltd. Lakshmi Machine Works Ltd. Larsen & Toubro Ltd. Latent View Analytics Ltd. Laurus Labs Ltd. Laxmi Organic Industries Ltd. Lemon Tree Hotels Ltd. Life Insurance Corporation of India Linde India Ltd. Lupin Ltd. Lux Industries Ltd. MMTC Ltd. MRF Ltd. MTAR Technologies Ltd. Macrotech Developers Ltd. Mahanagar Gas Ltd. Mahindra & Mahindra Financial Services Ltd. Mahindra & Mahindra Ltd. Mahindra CIE Automotive Ltd. Mahindra Holidays & Resorts India Ltd. Mahindra Lifespace Developers Ltd. Mahindra Logistics Ltd. Manappuram Finance Ltd. Mangalore Refinery & Petrochemicals Ltd. Marico Ltd. Maruti Suzuki India Ltd. Mastek Ltd. Max Financial Services Ltd. Max Healthcare Institute Ltd. Mazagoan Dock Shipbuilders Ltd. Medplus Health Services Ltd. Meghmani Finechem Ltd. Metro Brands Ltd. Metropolis Healthcare Ltd. Motherson Sumi Wiring India Ltd. Motilal Oswal Financial Services Ltd. MphasiS Ltd. Multi Commodity Exchange of India Ltd. Muthoot Finance Ltd. NATCO Pharma Ltd. NBCC (India) Ltd. NCC Ltd. NHPC Ltd. NLC India Ltd. NMDC Ltd. NMDC Steel Ltd. NOCIL Ltd. NTPC Ltd. Narayana Hrudayalaya Ltd. National Aluminium Co. Ltd. Navin Fluorine International Ltd. Nazara Technologies Ltd. Nestle India Ltd. Network18 Media & Investments Ltd. Nippon Life India Asset Management Ltd. Nuvoco Vistas Corporation Ltd. Oberoi Realty Ltd. Oil & Natural Gas Corporation Ltd. Oil India Ltd. Olectra Greentech Ltd. One 97 Communications Ltd. Oracle Financial Services Software Ltd. Orient Electric Ltd. PB Fintech Ltd. PCBL Ltd. PI Industries Ltd. PNB Housing Finance Ltd. PNC Infratech Ltd. PVR INOX Ltd. Page Industries Ltd. Patanjali Foods Ltd. Persistent Systems Ltd. Petronet LNG Ltd. Pfizer Ltd. Phoenix Mills Ltd. Pidilite Industries Ltd. Piramal Enterprises Ltd. Piramal Pharma Ltd. Poly Medicure Ltd. Polycab India Ltd. Polyplex Corporation Ltd. Poonawalla Fincorp Ltd. Power Finance Corporation Ltd. Power Grid Corporation of India Ltd. Praj Industries Ltd. Prestige Estates Projects Ltd. Prince Pipes and Fittings Ltd. Prism Johnson Ltd. Procter & Gamble Hygiene & Health Care Ltd. Punjab National Bank Quess Corp Ltd. RBL Bank Ltd. REC Ltd. RHI MAGNESITA INDIA LTD. RITES Ltd. Radico Khaitan Ltd Rail Vikas Nigam Ltd. Rain Industries Ltd Rainbow Childrens Medicare Ltd. Rajesh Exports Ltd. Rallis India Ltd. Rashtriya Chemicals & Fertilizers Ltd. Ratnamani Metals & Tubes Ltd. RattanIndia Enterprises Ltd. Raymond Ltd. Redington Ltd. Relaxo Footwears Ltd. Reliance Industries Ltd. Restaurant Brands Asia Ltd. Rossari Biotech Ltd. Route Mobile Ltd. SBI Cards and Payment Services Ltd. SBI Life Insurance Company Ltd. SJVN Ltd. SKF India Ltd. SRF Ltd. Samvardhana Motherson International Ltd. Sanofi India Ltd. Sapphire Foods India Ltd. Schaeffler India Ltd. Sharda Cropchem Ltd. Shoppers Stop Ltd. Shree Cement Ltd. Shree Renuka Sugars Ltd. Shriram Finance Ltd. Shyam Metalics and Energy Ltd. Siemens Ltd. Sobha Ltd. Solar Industries India Ltd. Sona BLW Precision Forgings Ltd. Sonata Software Ltd. Star Health and Allied Insurance Company Ltd. State Bank of India Steel Authority of India Ltd. Sterling and Wilson Renewable Energy Ltd. Sterlite Technologies Ltd. Sumitomo Chemical India Ltd. Sun Pharma Advanced Research Company Ltd. Sun Pharmaceutical Industries Ltd. Sun TV Network Ltd. Sundaram Finance Ltd. Sundram Fasteners Ltd. Sunteck Realty Ltd. Suprajit Engineering Ltd. Supreme Industries Ltd. Suven Pharmaceuticals Ltd. Suzlon Energy Ltd. Swan Energy Ltd. Syngene International Ltd. TCI Express Ltd. TCNS Clothing Co. Ltd. TTK Prestige Ltd. TV18 Broadcast Ltd. TVS Motor Company Ltd. Tamilnad Mercantile Bank Ltd. Tanla Platforms Ltd. Tata Chemicals Ltd. Tata Communications Ltd. Tata Consultancy Services Ltd. Tata Consumer Products Ltd. Tata Elxsi Ltd. Tata Investment Corporation Ltd. Tata Motors Ltd DVR Tata Motors Ltd. Tata Power Co. Ltd. Tata Steel Ltd. Tata Teleservices (Maharashtra) Ltd. Teamlease Services Ltd. Tech Mahindra Ltd. Tejas Networks Ltd. The New India Assurance Company Ltd. The Ramco Cements Ltd. Thermax Ltd. Timken India Ltd. Titan Company Ltd. Torrent Pharmaceuticals Ltd. Torrent Power Ltd. Transport Corporation of India Ltd. Trent Ltd. Trident Ltd. Triveni Engineering & Industries Ltd. Triveni Turbine Ltd. Tube Investments of India Ltd. UCO Bank UFLEX Ltd. UNO Minda Ltd. UPL Ltd. UTI Asset Management Company Ltd. UltraTech Cement Ltd. Union Bank of India United Breweries Ltd. United Spirits Ltd. V-Guard Industries Ltd. V-Mart Retail Ltd. V.I.P. Industries Ltd. Vaibhav Global Ltd. Vardhman Textiles Ltd. Varroc Engineering Ltd. Varun Beverages Ltd. Vedant Fashions Ltd. Vedanta Ltd. Vijaya Diagnostic Centre Ltd. Vinati Organics Ltd. Vodafone Idea Ltd. Voltas Ltd. Welspun Corp Ltd. Welspun India Ltd. Westlife Development Ltd. Whirlpool of India Ltd. Wipro Ltd. Yes Bank Ltd. ZF Commercial Vehicle Control Systems India Ltd. Zee Entertainment Enterprises Ltd. Zensar Technolgies Ltd. Zomato Ltd. Zydus Lifesciences Ltd. Zydus Wellness Ltd. eClerx Services Ltd.

Sunday, March 26, 2023

Important Quotes of good bye

Thank you for the work you have done for Viridor, your support has been invaluable. Wish you the very best in your future endeavors.

Monday, February 20, 2023

News Extrator

 using Newtonsoft.Json;

using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using System.Net;

using System.Text;

using System.Threading.Tasks;


namespace NewsExtractor

{

    class Program

    {

        static void Main(string[] args)

        {


            NewsEntities newsEntities = new NewsEntities();

            var list = newsEntities.NewsURLs;

            foreach (var url in list)

            {

                var data = GetURLData(url.URL.Replace("200", url.Count.ToString()));

                AddNews(data);      

            }

        }


        private static string GetURLData(string url)

        {

            Console.WriteLine(url);

            WebClient client = new WebClient();


            client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36)");


            Stream data = client.OpenRead(url);

            StreamReader reader = new StreamReader(data);

            var s = reader.ReadToEnd();

            data.Close();

            reader.Close();

            return s;

        }


        private static void AddNews(string fileData)

        {

            NewsEntities newsEntities = new NewsEntities();


            var weatherForecast = JsonConvert.DeserializeObject<RootNew>(fileData);

            foreach (var item in weatherForecast.data.items)

            {

                if (!newsEntities.News.Any(p => p.TickerTapeId == item._id))

                {

                    News n = new News();

                    n.Title = item.title;

                    n.TickerTapeId = item._id;

                    n.Description = item.description;

                    n.NewsDate2 = item.date;

                    n.NewsDate = item.date.ToString();

                    n.Image = item.image;

                    n.Stocks = string.Join(",", item.stocks.Select(p => p.sid));

                    n.link = item.link;

                    newsEntities.News.Add(n);

                    Console.WriteLine(item.title);


                }

            }

            newsEntities.SaveChanges();

        }

    }



}


Featured Post

Links

https://www.examtopics.com/discussions/microsoft/view/52755-exam-pl-600-topic-2-question-4-discussion/ https://www.examtopics.com/discussion...