Forty years before HBO’s “The Deuce” re-created the New York prostitution scene of 1971, New York Magazine writer Gail Sheehy published a series of groundbreaking articles on the same subject.

“Cleaning Up Hell’s Bedroom” describes the comings-and-goings at the Hotel Raymona, the “pross vans” that picked up the prostitutes off the streets and brought them for booking at Midtown North — and the connection between the city’s underworld to the mainstream.

Sheehy developed her articles into a book called “Hustling” that was filmed as an ABC TV-movie in 1975. It starred Lee Remick as “City Magazine” reporter Fran Morrison and a then-unknown Jill Clayburgh as Wanda, a prostitute who provides the journalist with a window into the world of $30 tricks. Unlike “The Deuce” — which took over two blocks in Washington Heights last summer to re-create Times Square with partial movie theater marquees and neighborhood restaurants turned into porn shots — “Hustling” was filmed in Times Square, when the old movie theaters still existed.

The entire film is available on YouTube. “I thought Jill Clayburgh was terrific in the role of Wanda,” Sheehy says. “I was staying at the Beverly Hills hotel. She woke me up at six in the morning so I could teach her about streetwalkers. She was so hungry to get the role.”

Remick was another story. She would not accept notes from Sheehy on set. “She didn’t know how to hold a tape recorder,” Sheehy says. “You never let anybody see your tape recorder. Lee Remick had just come from playing Lady Churchill [in the miniseries “Jennie: Lady Randolph Churchill”]. She was playing a top aristocrat and was still in that frame of mind.”

When Sheehy watched the premiere of “The Deuce” Sunday night, she thought the show was “entertaining,” but felt that some of the dialogue, particularly from Maggie Gyllenhaal— playing a prostitute named Candy — was taken from her articles. “Some of the lines, word for word, were out of my article,” Sheehy says. “I felt it was just the same [with Maggie] leaning into the [car] window, picking the youngest, scared kid in the car full of boys, telling him there’s no kissing and you have to wear [a condom].”

And she had issues about the series’ portrayal of the prostitutes. “The girls are depicted as so dumb and crude, I wondered how long you could be interested in them,” Sheehy says. “The girls on the East Side were perky and savvy and they had snappy lines. They weren’t looking all lumpy and grumpy. They were having fun.”

While the series concentrates on the Times Square underworld, Sheehy says the scene was branching out to the East Side of Manhattan, with pimps and prostitutes working in pairs and targeting men staying at the Waldorf-Astoria.

“My main source was Bobby the Doorman. We sat on the back-door steps of all the Waldorf,” she says. “The pimps put their girls on the streets by the [hotel] to pull off heists, getting a john into the cars, fleecing their wallets while getting undressed. Or throwing their clothes down [the hotel] incinerator and robbing them.”

“The Deuce” executive producer George Pelecanos told The Post that Sheehy was the inspiration for Sandra Washington, an African-American reporter from The Amsterdam News looking to do the same kind of story Sheehy did for New York magazine. “So, now I’m black,” Sheehy says, with a laugh. Though Pelecanos says the producers have “had a tip” that Sheehy “would like to speak to us,” Sheehy says she has never spoken to anyone associated with the production — and didn’t even know what the show was when she first heard about it.

And that title (which refers to an old nickname for 42nd Street)? In her year-and-a-half talking to prostitutes and other denizens for her articles, Sheehy says, “I never heard the term ‘the Deuce.’ ”